Implement dark mode support using a new ThemeState service that manages theme switching and integrates with DevExpress Blazor theming. Update App.razor to apply the theme globally, enhance MainLayout with a toggle button and dynamic CSS classes, and add dark mode styles to CSS files. Register ThemeState as a scoped service in Program.cs.
61 lines
1.7 KiB
C#
61 lines
1.7 KiB
C#
using DbFirst.BlazorWebApp.Components;
|
|
using DbFirst.BlazorWebApp.Services;
|
|
using DevExpress.Blazor;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Add services to the container.
|
|
builder.Services.AddRazorComponents()
|
|
.AddInteractiveServerComponents();
|
|
|
|
builder.Services.AddDevExpressBlazor(options => options.BootstrapVersion = BootstrapVersion.v5);
|
|
builder.Services.AddScoped<ThemeState>();
|
|
|
|
var apiBaseUrl = builder.Configuration["ApiBaseUrl"];
|
|
if (!string.IsNullOrWhiteSpace(apiBaseUrl))
|
|
{
|
|
builder.Services.AddHttpClient<CatalogApiClient>(client =>
|
|
{
|
|
client.BaseAddress = new Uri(apiBaseUrl);
|
|
});
|
|
builder.Services.AddHttpClient<DashboardApiClient>(client =>
|
|
{
|
|
client.BaseAddress = new Uri(apiBaseUrl);
|
|
});
|
|
builder.Services.AddHttpClient<MassDataApiClient>(client =>
|
|
{
|
|
client.BaseAddress = new Uri(apiBaseUrl);
|
|
});
|
|
builder.Services.AddHttpClient<LayoutApiClient>(client =>
|
|
{
|
|
client.BaseAddress = new Uri(apiBaseUrl);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
builder.Services.AddHttpClient<CatalogApiClient>();
|
|
builder.Services.AddHttpClient<DashboardApiClient>();
|
|
builder.Services.AddHttpClient<MassDataApiClient>();
|
|
builder.Services.AddHttpClient<LayoutApiClient>();
|
|
}
|
|
|
|
var app = builder.Build();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (!app.Environment.IsDevelopment())
|
|
{
|
|
app.UseExceptionHandler("/Error", createScopeForErrors: true);
|
|
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
|
app.UseHsts();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseStaticFiles();
|
|
app.UseAntiforgery();
|
|
|
|
app.MapRazorComponents<App>()
|
|
.AddInteractiveServerRenderMode();
|
|
|
|
app.Run();
|