using DatabaseTest.Components; using DatabaseTest.Models; using DatabaseTest.Services; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddRazorComponents() .AddInteractiveServerComponents(); builder.Services.AddSingleton(); builder.Services.AddScoped(); var app = builder.Build(); try { using var scope = app.Services.CreateScope(); var configService = scope.ServiceProvider.GetRequiredService(); var dbService = scope.ServiceProvider.GetRequiredService(); if (configService.ProviderType == DatabaseProviderType.PostgreSQL) { _ = dbService.ApplyMigrationsAsync(); } else { _ = dbService.EnsureDatabaseCreatedAsync(); } } catch { // Ignore if database is temporarily offline on startup } // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error", true); app.UseHsts(); } app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true); app.UseHttpsRedirection(); app.UseAntiforgery(); app.MapStaticAssets(); app.MapRazorComponents() .AddInteractiveServerRenderMode(); app.Run();