Files
ChronoCCG/Chrono/Server/Program.cs
T
2026-07-03 14:38:24 -04:00

51 lines
1.4 KiB
C#

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<CardRenderingService>();
builder.Services.AddScoped<AnalyticsService>();
builder.Services.AddHttpClient();
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
builder.Services.AddDbContext<AppDbContext>(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<AppDbContext>();
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<App>()
.AddInteractiveServerRenderMode()
.AddAdditionalAssemblies(typeof(Home).Assembly);
app.Run();