Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
</ItemGroup>

<ItemGroup Label="Aspire — client integrations (consumed by the API)">
<PackageVersion Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" Version="13.5.2" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.3" />
<!-- Backs the AddDbContextCheck<AppDbContext>() readiness probe in samples/SampleApp. -->
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="10.0.11" />
<PackageVersion Include="Aspire.StackExchange.Redis" Version="13.5.2" />
<!-- Referenced only when the matching provider block in Program.cs is uncommented. -->
<PackageVersion Include="Aspire.Npgsql" Version="13.5.2" />
Expand Down Expand Up @@ -78,9 +80,7 @@
<PackageVersion Include="Testcontainers.PostgreSql" Version="4.14.0" />
<PackageVersion Include="Testcontainers.MongoDb" Version="4.14.0" />
<PackageVersion Include="Testcontainers.MsSql" Version="4.14.0" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="6.1.4" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.3" />
<PackageVersion Include="Npgsql" Version="10.0.3" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="6.1.6" />
</ItemGroup>

<ItemGroup Label="Testing">
Expand Down
5 changes: 5 additions & 0 deletions aspire/DotNetBoost.Settings.AppHost/AppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
.WithReference(redis)
.WaitFor(redis)
.WithEnvironment("Settings__EncryptionKey", encryptionKey)
// /health carries the AddDbContextCheck registered in samples/SampleApp/Program.cs, so
// this is what makes the dashboard's WaitFor(api) below hold until Postgres actually
// answers rather than merely until the process is up. MapDefaultEndpoints only maps
// /health in Development — drop this line if you ever publish this AppHost.
.WithHttpHealthCheck("/health")
.WithExternalHttpEndpoints();

// ── Dashboard — clients/dashboard (Nuxt) ─────────────────────────────────────
Expand Down
32 changes: 31 additions & 1 deletion samples/SampleApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using DotNetBoost.Settings.Core.Interfaces;
using Microsoft.EntityFrameworkCore;
using OpenTelemetry;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
using SampleApp;
using SampleApp.Caching;
using SampleApp.Settings;
Expand All @@ -23,7 +26,34 @@
// block, uncomment the one you want, flip the matching ItemGroup in SampleApp.csproj,
// the provider block in AppHost.cs, and the DatabaseProvider in AppDbContext.cs.
// ─────────────────────────────────────────────────────────────────────────────
builder.AddNpgsqlDbContext<AppDbContext>("settingsdb");
builder.Services.AddDbContext<AppDbContext>(opt =>
opt.UseNpgsql(
builder.Configuration.GetConnectionString("settingsdb"),
// A cold Postgres container refuses a few connections before it accepts any, so
// retry transient failures instead of failing the first request after a restart.
// Bounded deliberately: the readiness probe below runs through this same strategy,
// and the default policy (6 retries backing off to 30s) makes it take about a
// minute to report a database that is plainly gone.
npgsql => npgsql.EnableRetryOnFailure(
maxRetryCount: 3,
maxRetryDelay: TimeSpan.FromSeconds(2),
errorCodesToAdd: null)));

// The two registrations below come free with Aspire.Npgsql.EntityFrameworkCore.PostgreSQL
// and have to be written out when the plain provider is used, as it is here:
// readiness — without it /health answers Healthy while Postgres is unreachable, which
// makes it useless to anything that gates traffic on it. Nothing polls it
// today: add .WithHttpHealthCheck("/health") to the api resource in
// AppHost.cs to make WaitFor(api) wait on the database too.
// telemetry — Npgsql's ActivitySource and Meter, so a trace on the dashboard shows the
// SQL a request ran instead of stopping at the HTTP span, and the Metrics
// page carries the connection-pool counters.
builder.Services.AddHealthChecks()
.AddDbContextCheck<AppDbContext>();

builder.Services.AddOpenTelemetry()
.WithTracing(tracing => tracing.AddSource("Npgsql"))
.WithMetrics(metrics => metrics.AddMeter("Npgsql"));

// ─────────────────────────────────────────────────────────────────────────────
// Storage provider — ALTERNATIVE: SQL Server (Entity Framework Core)
Expand Down
3 changes: 2 additions & 1 deletion samples/SampleApp/SampleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
in Program.cs and the container started by aspire/DotNetBoost.Settings.AppHost.
-->
<ItemGroup Label="Storage provider — ACTIVE: PostgreSQL (EF Core)">
<PackageReference Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" />
</ItemGroup>

<ItemGroup Label="Storage provider — ALTERNATIVE: MongoDB">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@
<PackageReference Include="Microsoft.Data.SqlClient" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" />
<PackageReference Include="Npgsql" />
</ItemGroup>
</Project>
Loading