Method AddDatabaseHealthAndTelemetry
- Namespace
- MailFathom.Infrastructure
- Assembly
- MailFathom.Infrastructure.dll
AddDatabaseHealthAndTelemetry(IHostApplicationBuilder, TimeSpan, IReadOnlyCollection<string>)
Makes the EF Core context report its health and publish database traces and metrics.
public static IHostApplicationBuilder AddDatabaseHealthAndTelemetry(this IHostApplicationBuilder builder, TimeSpan commandTimeout, IReadOnlyCollection<string> probeTags)
Parameters
builderIHostApplicationBuilderThe host application builder the context is already registered on.
commandTimeoutTimeSpanHow long a single database command may run before it is cancelled.
probeTagsIReadOnlyCollection<string>The health-check tags that decide which probes consult the database, stated by the composition root that owns the probes.
Returns
- IHostApplicationBuilder
The builder, for chaining.
Remarks
This is deliberately the enrichment half of the Aspire PostgreSQL EF Core integration rather than its
AddNpgsqlDbContext half. That method resolves a connection string from
ConnectionStrings at registration time and builds the context around it, which MailFathom cannot use: the
connection string is composed asynchronously during startup because resolving a secret reference is asynchronous,
and the password is supplied per physical connection so a rotated credential needs no restart. Enrichment layers
the health check, the tracing, and the metrics onto the context the infrastructure already registered, so a
deployment that runs without any orchestrator — reading Persistence:ConnectionString or
Persistence:Password from its own secret store — gets the same telemetry as one Aspire starts.
Retries stay off. A retrying execution strategy refuses the user-initiated transaction
MailFathom.Infrastructure.Persistence.Sessions.PersistenceSessionFactory opens for every session, so enabling it would fail every write at
session start rather than merely leave it un-retried, and it would nest inside the outbound resilience pipeline
that already governs database command execution. Adopting retries instead means handing each unit of work to
Database.CreateExecutionStrategy().ExecuteAsync and dropping that pipeline from the same paths.
Exceptions
- ArgumentNullException
Thrown when
builderorprobeTagsis null.- ArgumentOutOfRangeException
Thrown when
commandTimeoutis not a positive duration.- InvalidOperationException
Thrown when the context has not been registered yet.