finalize entry point to program

This commit is contained in:
Jonas Seiler 2025-04-03 14:01:54 +02:00
parent fe358e44a3
commit 975dfb2086

View File

@ -1,8 +1,11 @@
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<StreetDbContext>(options => options.UseNpgsql("TBD", o => o.UseNetTopologySuite()));
// In testing, the framework replaces the DBContext anyways.
// In Production, this is set in the compose or k8s config
var connectionString = Environment.GetEnvironmentVariable("CONNECTION_STRING");
builder.Services.AddDbContext<StreetDbContext>(options => options.UseNpgsql(connectionString, o => o.UseNetTopologySuite()));
builder.Services.AddScoped<StreetRepository>();
builder.Services.AddScoped<StreetService>();
@ -11,6 +14,10 @@ builder.Services.AddControllers();
var app = builder.Build();
using var scope = app.Services.CreateScope();
var dbContext = scope.ServiceProvider.GetRequiredService<StreetDbContext>();
dbContext.Database.Migrate();
app.UseRouting();
app.MapControllers();