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<ApplicationContext>(gerbilmanager) replaces manual AddDbContext/UseNpgsql + appsettings connection string Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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<Projects.GerbilManagerWebAPI>("webapi")
|
||||
.WithReference(gerbilDb)
|
||||
.WaitFor(gerbilDb);
|
||||
|
||||
builder.Build().Run();
|
||||
|
||||
@@ -8,4 +8,12 @@
|
||||
<UserSecretsId>b153f50c-bec1-401e-9893-f9df7cff2ebd</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Aspire.Hosting.PostgreSQL" Version="13.4.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\GerbilManagerWebAPI\GerbilManagerWebAPI.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" Version="13.4.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.8">
|
||||
|
||||
@@ -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<ApplicationContext>(opts => opts.UseNpgsql(builder.Configuration.GetConnectionString("gerbilmanager")));
|
||||
builder.AddNpgsqlDbContext<ApplicationContext>("gerbilmanager");
|
||||
builder.Services.AddScoped<UnitOfWork>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
Reference in New Issue
Block a user