2022-11-10 19:59:35 +01:00
|
|
|
using labdb.Models;
|
2022-11-10 22:27:31 +01:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
2022-11-10 19:59:35 +01:00
|
|
|
|
|
|
|
namespace labdb;
|
|
|
|
|
|
|
|
public static class Program
|
|
|
|
{
|
|
|
|
public static void Main(string[] args)
|
|
|
|
{
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
2022-11-19 22:46:32 +01:00
|
|
|
builder.Host.UseSystemd();
|
|
|
|
|
2022-11-10 19:59:35 +01:00
|
|
|
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ??
|
|
|
|
throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
|
|
|
|
builder.Services.AddDbContextFactory<AppDbContext>(options => options
|
|
|
|
.UseNpgsql(connectionString, x => x
|
|
|
|
.UseNetTopologySuite()
|
|
|
|
)
|
|
|
|
.UseSnakeCaseNamingConvention()
|
|
|
|
.UseAllCheckConstraints()
|
|
|
|
);
|
|
|
|
|
|
|
|
builder.Services.AddRazorPages();
|
2022-11-10 22:27:31 +01:00
|
|
|
builder.Services.AddServerSideBlazor();
|
2022-11-10 19:59:35 +01:00
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
app.MigrateDatabase();
|
|
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
if (!app.Environment.IsDevelopment())
|
|
|
|
{
|
2022-11-10 22:27:31 +01:00
|
|
|
app.UseExceptionHandler("/Error");
|
2022-11-10 19:59:35 +01:00
|
|
|
}
|
|
|
|
|
2022-11-10 22:27:31 +01:00
|
|
|
|
2022-11-10 19:59:35 +01:00
|
|
|
app.UseStaticFiles();
|
|
|
|
|
|
|
|
app.UseRouting();
|
|
|
|
|
2022-11-10 22:27:31 +01:00
|
|
|
app.MapBlazorHub();
|
|
|
|
app.MapFallbackToPage("/_Host");
|
2022-11-10 19:59:35 +01:00
|
|
|
|
|
|
|
app.Run();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void MigrateDatabase(this WebApplication app)
|
|
|
|
{
|
|
|
|
var dbContextFactory = app.Services.GetRequiredService<IDbContextFactory<AppDbContext>>();
|
|
|
|
using var dbContext = dbContextFactory.CreateDbContext();
|
|
|
|
dbContext.Database.Migrate();
|
|
|
|
}
|
|
|
|
}
|