using Microsoft.EntityFrameworkCore; using Server; using Server.Components; using Shared.Pages; using Shared.Services; var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddRazorComponents().AddInteractiveServerComponents(); builder.Services.AddTelerikBlazor(); builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddHttpClient(); 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(Home).Assembly); app.Run();