From 84de905469784b73bc2c64ccb1b750d0412a8ff0 Mon Sep 17 00:00:00 2001 From: Gulum Date: Fri, 5 Jun 2026 23:36:06 +0200 Subject: [PATCH] ARCH-2: wire PostgreSQL through Aspire - AppHost: AddPostgres(postgres).WithDataVolume() + AddDatabase(gerbilmanager), WebAPI project resource WithReference/WaitFor on the db (Aspire-generated credentials) - WebAPI: AddNpgsqlDbContext(gerbilmanager) replaces manual AddDbContext/UseNpgsql + appsettings connection string Co-Authored-By: Claude Opus 4.8 (1M context) --- GerbilManager.AppHost/AppHost.cs | 15 ++++++++++++--- .../GerbilManager.AppHost.csproj | 8 ++++++++ GerbilManagerWebAPI/GerbilManagerWebAPI.csproj | 1 + GerbilManagerWebAPI/Program.cs | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/GerbilManager.AppHost/AppHost.cs b/GerbilManager.AppHost/AppHost.cs index 97422e2..3f842d4 100644 --- a/GerbilManager.AppHost/AppHost.cs +++ b/GerbilManager.AppHost/AppHost.cs @@ -1,3 +1,12 @@ -var builder = DistributedApplication.CreateBuilder(args); - -builder.Build().Run(); +var builder = DistributedApplication.CreateBuilder(args); + +var postgres = builder.AddPostgres("postgres") + .WithDataVolume(); + +var gerbilDb = postgres.AddDatabase("gerbilmanager"); + +builder.AddProject("webapi") + .WithReference(gerbilDb) + .WaitFor(gerbilDb); + +builder.Build().Run(); diff --git a/GerbilManager.AppHost/GerbilManager.AppHost.csproj b/GerbilManager.AppHost/GerbilManager.AppHost.csproj index 9300699..475f60d 100644 --- a/GerbilManager.AppHost/GerbilManager.AppHost.csproj +++ b/GerbilManager.AppHost/GerbilManager.AppHost.csproj @@ -8,4 +8,12 @@ b153f50c-bec1-401e-9893-f9df7cff2ebd + + + + + + + + diff --git a/GerbilManagerWebAPI/GerbilManagerWebAPI.csproj b/GerbilManagerWebAPI/GerbilManagerWebAPI.csproj index 7897860..6c68de5 100644 --- a/GerbilManagerWebAPI/GerbilManagerWebAPI.csproj +++ b/GerbilManagerWebAPI/GerbilManagerWebAPI.csproj @@ -7,6 +7,7 @@ + diff --git a/GerbilManagerWebAPI/Program.cs b/GerbilManagerWebAPI/Program.cs index 2e5a64d..e04a6fc 100644 --- a/GerbilManagerWebAPI/Program.cs +++ b/GerbilManagerWebAPI/Program.cs @@ -11,7 +11,7 @@ builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); -builder.Services.AddDbContext(opts => opts.UseNpgsql(builder.Configuration.GetConnectionString("gerbilmanager"))); +builder.AddNpgsqlDbContext("gerbilmanager"); builder.Services.AddScoped(); var app = builder.Build();