With Aspire 13 client integrations, how do the Aspire:* configuration sections, the Disable* settings and the configureSettings delegate combine, and when would you switch a feature off?
answer
- one settings class per client package
- Aspire:Npgsql:EntityFrameworkCore:PostgreSQL
- ConnectionStrings:name beats the section
- the delegate runs last
- DisableHealthChecks for an optional dependency
basics
~20 sEach client package binds a settings class from its Aspire:* section, lets ConnectionStrings:<name> override the connection string, then runs the configureSettings delegate last. Disable* flags turn off retries, health checks, tracing or metrics per client.
solid answer
~30 sEvery client integration has a settings class — `NpgsqlEntityFrameworkCorePostgreSQLSettings` for EF Core with Npgsql, `StackExchangeRedisSettings` for Redis. `AddNpgsqlDbContext<RecipesDbContext>("recipesdb")` binds `Aspire:Npgsql:EntityFrameworkCore:PostgreSQL`, then its `recipesdb` sub-section, then its `RecipesDbContext` sub-section; a `ConnectionStrings:recipesdb` value then replaces any `ConnectionString` found there, and the optional `configureSettings` delegate runs last, so code wins. The switches are `DisableRetry`, `DisableHealthChecks`, `DisableTracing`, `DisableMetrics` and `CommandTimeout` for EF Core; `DisableHealthChecks`, `DisableTracing` and `DisableAutoActivation` (default `true`) for Redis. Switch one off for a reason: `DisableRetry` when you own the execution strategy or transactions, `DisableHealthChecks` when a cache is optional and should not fail readiness, `DisableTracing` when the spans duplicate another source.
code
json · 18 lines{
"Aspire": {
"Npgsql": {
"EntityFrameworkCore": {
"PostgreSQL": {
"CommandTimeout": 15,
"RecipesDbContext": { "DisableMetrics": true }
}
}
},
"StackExchange": {
"Redis": {
"DisableHealthChecks": true,
"ConfigurationOptions": { "ConnectTimeout": 3000 }
}
}
}
}go deeper
Recall that each client package reads its own Aspire:* section and has Disable* switches, and that the settings can also be changed in code.
Explain the binding order: base section, named and type sub-sections, ConnectionStrings override, delegate last. Name the switches each package actually has.
Argue when a switch is right: drop a health check for an optional cache so readiness does not fail, keep retries but move transactions into the execution strategy, and treat Redis's eager activation as a startup dependency.
Decide which defaults the solution standardises in shared configuration and which each service may override, so health and tracing behave the same across services.
## One settings object per client An Aspire **client integration** is configured through a plain settings class that it fills from configuration before it registers anything. In the recipe service: | Package | Settings class | Configuration section | |---|---|---| | `Aspire.Npgsql.EntityFrameworkCore.PostgreSQL` | `NpgsqlEntityFrameworkCorePostgreSQLSettings` | `Aspire:Npgsql:EntityFrameworkCore:PostgreSQL` | | `Aspire.StackExchange.Redis` | `StackExchangeRedisSettings` | `Aspire:StackExchange:Redis` | The properties are booleans that default to `false` (features on) plus a few values: - **EF Core with Npgsql:** `ConnectionString`, `DisableRetry`, `DisableHealthChecks`, `DisableTracing`, `DisableMetrics`, `CommandTimeout` (seconds, unset by default). - **Redis:** `ConnectionString`, `DisableHealthChecks`, `DisableTracing`, and `DisableAutoActivation`, which defaults to **`true`** — the one switch that starts out on. Each package ships a `ConfigurationSchema.json` that it contributes to the `appsettings.json` JSON schema, so editors can complete these keys. ## The order values are applied For `builder.AddNpgsqlDbContext<RecipesDbContext>("recipesdb", configureSettings)` the source applies, in order: 1. the base section `Aspire:Npgsql:EntityFrameworkCore:PostgreSQL`; 2. its sub-section named after the connection, `...:PostgreSQL:recipesdb`; 3. its sub-section named after the context type, `...:PostgreSQL:RecipesDbContext`, if it exists; 4. `ConnectionStrings:recipesdb`, which replaces `ConnectionString` when present; 5. the `configureSettings` delegate, which can change anything. Redis follows the same idea with the base section, then the `cache` sub-section, then `ConnectionStrings:cache`, then the delegate. Redis adds one more layer: a `ConfigurationOptions` sub-key binds StackExchange.Redis's own `ConfigurationOptions` (timeouts, `Ssl`, `ClientName`), and an optional `configureOptions` delegate edits that object last. The practical rule is that **code beats configuration** and **ConnectionStrings beats the Aspire section** for the connection string itself. A `ConnectionString` written under `Aspire:...` is therefore a fallback for environments that do not set `ConnectionStrings`. ## When to switch a feature off | Setting | Switch it when | Cost of switching | |---|---|---| | `DisableRetry` | you configure your own execution strategy, or legacy code opens transactions outside `CreateExecutionStrategy` | transient failures surface immediately | | `DisableHealthChecks` | the dependency is optional (a cache the API can run without) and should not fail readiness, or you register a better check yourself | the health endpoint stops reflecting that dependency | | `DisableTracing` | the spans duplicate another instrumentation or cost too much volume | database or Redis calls vanish from traces | | `DisableMetrics` (EF Core only) | the meters are collected elsewhere | no pool or command metrics | | `DisableAutoActivation = false` (Redis) | you want the connection attempted at startup rather than on first use | startup now depends on Redis being reachable sooner | The health check deserves care. When the recipe API's readiness endpoint includes the Redis check, an outage of a cache that the API could serve around takes every instance out of rotation. Turning the check off, or registering your own check that degrades instead of failing, keeps a cache incident from becoming an API outage. Conversely, the database check is usually worth keeping: the API cannot serve recipes without it. ## Duplicate registrations are ignored The integration adds each health check only once per name — it records `Aspire.HealthChecks.<name>` in the host builder's properties — so a second registration that resolves to the same check name does not add a second check. ## Per-context settings in practice The type sub-section is what makes one section serve several contexts. If the recipe API also has an `AuditDbContext`, a `CommandTimeout` under the base section applies to both, while `...:PostgreSQL:AuditDbContext:DisableHealthChecks` removes only the audit context's check. Because the connection-name sub-section is bound before the type sub-section, a value under `...:PostgreSQL:RecipesDbContext` wins over the same key under `...:PostgreSQL:recipesdb`. ## Mistakes to avoid - Writing `"DisableHealthChecks": true` under the `Aspire:StackExchange:Redis` section and expecting it to affect the PostgreSQL client: every package reads only its own section. - Expecting `ConnectionString` under the Aspire section to override the reference the AppHost injected — `ConnectionStrings:<name>` wins. - Turning off retries to "fix" the user-transaction error without reading why it happened; wrapping the transaction in the execution strategy keeps the resilience.
- Where does a ConnectionString under Aspire:Npgsql:EntityFrameworkCore:PostgreSQL still matter?Only where no `ConnectionStrings:recipesdb` value exists — for example a test or a host that sets the Aspire section but no ConnectionStrings entry. Whenever the AppHost reference or a deployment supplies `ConnectionStrings:recipesdb`, that value replaces it before the `configureSettings` delegate runs.
- Why is DisableAutoActivation true by default for Redis but there is no such switch for the DbContext?The Redis multiplexer is a singleton that connects in its factory; activating it at startup would tie startup to Redis being reachable. A pooled DbContext opens connections only when a query runs, so there is nothing to activate early. Setting `DisableAutoActivation` to `false` opts Redis into eager connection.
- A ConnectionString under the Aspire section overrides the one the AppHost reference injects.
- Every Aspire switch defaults to false, including DisableAutoActivation for Redis.
- DisableHealthChecks under Aspire:StackExchange:Redis also removes the PostgreSQL context's check.
- The configureSettings delegate runs first and configuration overwrites it.
- StackExchangeRedisSettings has DisableMetrics just like the Npgsql settings class.