51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
using DatabaseTest.Components;
|
|
using DatabaseTest.Models;
|
|
using DatabaseTest.Services;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Add services to the container.
|
|
builder.Services.AddRazorComponents()
|
|
.AddInteractiveServerComponents();
|
|
|
|
builder.Services.AddSingleton<IDatabaseConfigService, DatabaseConfigService>();
|
|
builder.Services.AddScoped<IDatabaseService, DatabaseService>();
|
|
|
|
var app = builder.Build();
|
|
|
|
try
|
|
{
|
|
using var scope = app.Services.CreateScope();
|
|
var configService = scope.ServiceProvider.GetRequiredService<IDatabaseConfigService>();
|
|
var dbService = scope.ServiceProvider.GetRequiredService<IDatabaseService>();
|
|
if (configService.ProviderType == DatabaseProviderType.PostgreSQL)
|
|
{
|
|
_ = dbService.ApplyMigrationsAsync();
|
|
}
|
|
else
|
|
{
|
|
_ = dbService.EnsureDatabaseCreatedAsync();
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
// Ignore if database is temporarily offline on startup
|
|
}
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (!app.Environment.IsDevelopment())
|
|
{
|
|
app.UseExceptionHandler("/Error", true);
|
|
app.UseHsts();
|
|
}
|
|
|
|
app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true);
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseAntiforgery();
|
|
|
|
app.MapStaticAssets();
|
|
app.MapRazorComponents<App>()
|
|
.AddInteractiveServerRenderMode();
|
|
|
|
app.Run(); |