Files
ApplianceRepair/Program.cs

56 lines
1.4 KiB
C#
Raw Normal View History

2026-02-03 16:55:37 -06:00
using ApplianceRepair;
using ApplianceRepair.Components;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.AddDbContext<DatabaseContext>(options =>
options.UseSqlite("Data Source=site.db"));
builder.Services.AddMemoryCache();
builder.Services.AddLogging();
builder.Services.AddScoped<BusinessConfigReader>();
builder.Services.AddScoped<ContentCardReader>();
builder.Services.AddScoped<HomePageReader>();
2026-04-25 13:14:08 -05:00
builder.Services.AddScoped<RepairRequestReader>();
builder.Services.AddScoped<RepairRequestMediaReader>();
2026-02-03 16:55:37 -06:00
2026-04-25 13:14:08 -05:00
var app = builder.Build();
2026-02-03 16:55:37 -06:00
using (var scope = app.Services.CreateScope())
{
var services = scope.ServiceProvider;
try
{
2026-04-25 13:14:08 -05:00
var context = services.GetRequiredService<DatabaseContext>();
await context.Database.MigrateAsync();
await DatabaseContext.Initialize(context);
2026-02-03 16:55:37 -06:00
}
catch (Exception ex)
{
var logger = services.GetRequiredService<ILogger<Program>>();
2026-04-25 13:14:08 -05:00
logger.LogError(ex, "An error occurred while migrating or seeding the database.");
2026-02-03 16:55:37 -06:00
}
}
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
}
app.UseAntiforgery();
app.MapStaticAssets();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();