Added database models

This commit is contained in:
2025-01-20 17:43:05 +01:00
parent 00504ad485
commit 49b5339bb3
11 changed files with 242 additions and 2 deletions

View File

@@ -1,3 +1,6 @@
using HopFrame.Web;
using Portfolio.Api;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
@@ -5,6 +8,15 @@ var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenApi();
builder.AddServiceDefaults();
builder.AddNpgsqlDbContext<DatabaseContext>("data");
builder.Services.AddHopFrame(options => {
options.DisplayUserInfo(false);
options.AddDbContext<DatabaseContext>();
});
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
var app = builder.Build();
// Configure the HTTP request pipeline.
@@ -12,7 +24,17 @@ if (app.Environment.IsDevelopment()) {
app.MapOpenApi();
}
await using (var scope = app.Services.CreateAsyncScope()) {
var db = scope.ServiceProvider.GetRequiredService<DatabaseContext>();
await db.Database.EnsureCreatedAsync();
}
app.UseHttpsRedirection();
app.MapDefaultEndpoints();
app.UseAntiforgery();
app.MapStaticAssets();
app.MapRazorComponents<App>()
.MapHopFramePages();
app.Run();