using Microsoft.EntityFrameworkCore; using Server; var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddRazorComponents().AddInteractiveServerComponents(); builder.Services.AddTelerikBlazor(); builder.Services.AddSingleton(); var connectionString = builder.Configuration.GetConnectionString("DefaultConnection"); builder.Services.AddDbContext(options => { if (!string.IsNullOrEmpty(connectionString)) options.UseNpgsql(connectionString); }); var app = builder.Build(); // Apply migrations using (var scope = app.Services.CreateScope()) { try { var db = scope.ServiceProvider.GetRequiredService(); if (!string.IsNullOrEmpty(connectionString)) db.Database.Migrate(); } catch (Exception ex) { Console.WriteLine( $"[WARNING] Database migration failed: {ex.Message}. The application will continue without a database connection."); } } if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error"); } app.UseStaticFiles(); app.UseAntiforgery(); app.MapControllers(); app.MapRazorComponents() .AddInteractiveServerRenderMode() .AddAdditionalAssemblies(typeof(Shared.Pages.Home).Assembly); app.Run();