Files
ApplianceRepair/Program.cs
2026-04-22 20:09:26 -05:00

50 lines
1.2 KiB
C#

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>();
var app = builder.Build();
using (var scope = app.Services.CreateScope())
{
var services = scope.ServiceProvider;
try
{
services.GetRequiredService<DatabaseContext>().Database.EnsureCreated();
}
catch (Exception ex)
{
var logger = services.GetRequiredService<ILogger<Program>>();
logger.LogError(ex, "An error occurred creating the DB.");
}
}
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
}
app.UseAntiforgery();
app.MapStaticAssets();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();