Aspire hosting vs client integrations, what client integrations register (DI, health checks, telemetry, resilience, configuration), Azure hosting integrations with emulators, local provisioning and existing resources, customising generated Bicep, and community integrations.
Integrations come in two halves:
Aspire.Hosting.*, in the AppHost) model a resource: run SQL Server or Redis as a container, or generate Bicep for an Azure resource such as Service Bus or Storage.Aspire.*, in the service) register the SDK client in DI from a named connection string, plus health checks, OpenTelemetry and retries.For Azure, AddAzureServiceBus("messaging") either runs an emulator locally (RunAsEmulator()), provisions a real resource in your subscription during aspire run, or points at an existing one. Deployed apps connect with managed identity. ConfigureInfrastructure lets you change the generated Bicep.
The trade-off: consistent, observable clients with very little code, versus an extra package layer whose defaults you must know and keep up to date.
"An integration is a pair of NuGet packages. The hosting side,
Aspire.Hosting.RedisorAspire.Hosting.Azure.ServiceBus, is referenced by the AppHost and describes the resource: run this container locally, or for Azure resources, generate the Bicep for it. The client side, likeAspire.StackExchange.RedisorAspire.Azure.Messaging.ServiceBus, is referenced by the service. One call such asbuilder.AddAzureServiceBusClient("messaging")reads the connection information by name, registers the SDK client in DI with the right lifetime, adds a health check, and turns on the SDK's tracing and metrics so it shows up in the dashboard and in Application Insights.Azure resources need a decision for local development. For Service Bus, Storage and Cosmos DB I can call
RunAsEmulator()so the AppHost runs the emulator container; otherwise Aspire provisions real resources in a development subscription duringaspire run, usingAzure:SubscriptionIdandAzure:Locationfrom user secrets, and caches them so the next run is quick. For a shared resource another team owns, I mark it as existing and pass its name and resource group as parameters. When deployed, the generated Bicep creates role assignments, and the client connects with managed identity rather than connection strings with keys. When the defaults don't meet our standards, such as SKU, tags, or disabling public network access, I change the Bicep model withConfigureInfrastructure.The mistake I see is assuming client integrations are required or magic. They're convenience wrappers: if a team needs full control of
ServiceBusClientOptions, they can register the SDK directly withGetConnectionString. Integrations buy consistency across many services, but the team still has to know what defaults they're applying."
| Hosting integration | Client integration | |
|---|---|---|
| Package | Aspire.Hosting.Redis, Aspire.Hosting.Azure.ServiceBus |
Aspire.StackExchange.Redis, Aspire.Azure.Messaging.ServiceBus |
| Referenced by | AppHost | Service |
| Does | Models or runs the resource; generates deployment infrastructure; registers resource health | Registers the client in DI; health checks; tracing and metrics; retries; config binding |
| Example | builder.AddRedis("cache") |
builder.AddRedisClient("cache") |
| Option | How | Fits | Watch out for |
|---|---|---|---|
| Emulator | .RunAsEmulator() |
Service Bus, Storage (Azurite), Cosmos DB, Event Hubs | Emulator feature gaps and limits |
| Real resource provisioned for you | User secrets Azure:SubscriptionId, Azure:Location, Azure:CredentialSource |
Services with no emulator; realistic testing | Cost; a dev subscription per team or developer |
| Existing resource | .AsExisting(nameParameter, resourceGroupParameter) |
Shared resources owned elsewhere | Needs RBAC for developers; shared state |
| Connection string only | AddConnectionString("legacy") |
Resources Aspire shouldn't manage | No Bicep, no role assignments |
A team had six services each creating their own ServiceBusClient with different retry settings and no tracing, so messages vanished from traces at the broker. Moving to the client integration and the hosting model gave every service the same retry policy, consumer spans linked to producers, and managed identity in place of [four] shared access keys. Mean time to find a stuck message dropped from [about an hour] to [a few minutes].
Checks whether the candidate understands the two halves of integrations, what they really add, and the practical decisions around Azure resources locally and in deployment.
Green flags
Red flags
AppHost (Aspire.Hosting.Azure.ServiceBus) Service (Aspire.Azure.Messaging.ServiceBus)
------------------------------------------ --------------------------------------------
var sb = builder.AddAzureServiceBus("messaging") builder.AddAzureServiceBusClient("messaging")
.RunAsEmulator(); -> reads ConnectionStrings:messaging
sb.AddServiceBusQueue("orders"); -> registers ServiceBusClient (singleton)
api.WithReference(sb); --- env var -------------> -> health check, tracing, metrics
ConnectionStrings:{name} (a full connection string, or just an endpoint/namespace for Azure resources, combined with DefaultAzureCredential).Aspire:{Provider}:{Component} (e.g. Aspire:Azure:Messaging:ServiceBus) and any delegate you pass.AddKeyedRedisClient).DisableHealthChecks is set.ActivitySource and Meter for OpenTelemetry, unless disabled.Azure hosting integrations build an in-memory infrastructure model using the Azure.Provisioning libraries. At publish time it becomes Bicep. ConfigureInfrastructure(infra => ...) gives you typed access to that model to change SKUs, tags or network settings. Role assignments for the consuming app's managed identity are generated too, so the deployed client uses Entra ID tokens instead of keys.
When an Azure resource isn't emulated, the AppHost provisions it in a resource group in the configured subscription during the run, stores the outputs locally and reuses them next time. That gives realistic behaviour (real limits, real RBAC) at the cost of Azure spend and the need for developers to have rights in a dev subscription.
| Resource | Local recommendation |
|---|---|
| SQL Server, PostgreSQL, Redis | Container (hosting integration) |
| Service Bus, Storage, Cosmos DB | Emulator, with an occasional run against real resources |
| Key Vault, OpenAI, resources with no emulator | Real resource in a dev subscription, or existing shared one |
The Aspire Community Toolkit adds integrations (for example extra databases and tools). Treat them like any third-party dependency: check maintenance, versions and licence.
Aspire.Hosting.Azure.ServiceBus to an AppHost, create a queue, call RunAsEmulator() and send a message from an API using the client integration.RunAsEmulator(), set Azure:SubscriptionId and Azure:Location in user secrets, and watch the resource group appear in the portal.ConfigureInfrastructure to set a tag, run aspire publish, and find it in the generated Bicep.ServiceBusClient without the integration and compare what appears in the dashboard.AppHost with Azure resources (emulated locally, managed identity when deployed), and the service consuming them.
// AppHost/Program.cs
using Azure.Provisioning.ServiceBus;
var builder = DistributedApplication.CreateBuilder(args);
var messaging = builder.AddAzureServiceBus("messaging")
.RunAsEmulator() // local: emulator container, no Azure cost
.ConfigureInfrastructure(infra => // deployed: tweak generated Bicep
{
var ns = infra.GetProvisionableResources().OfType<ServiceBusNamespace>().Single();
ns.Sku = new ServiceBusSku { Name = ServiceBusSkuName.Standard };
ns.Tags.Add("cost-centre", "orders");
});
messaging.AddServiceBusQueue("orders");
var storage = builder.AddAzureStorage("storage").RunAsEmulator(); // Azurite locally
var invoices = storage.AddBlobs("invoices");
builder.AddProject<Projects.Orders_Api>("api")
.WithReference(messaging)
.WithReference(invoices);
builder.Build().Run();
// Orders.Api/Program.cs
using Azure.Messaging.ServiceBus;
var builder = WebApplication.CreateBuilder(args);
builder.AddServiceDefaults();
// Client integrations: DI registration + health checks + tracing/metrics.
builder.AddAzureServiceBusClient("messaging");
builder.AddAzureBlobServiceClient("invoices");
var app = builder.Build();
app.MapPost("/orders", async (OrderRequest req, ServiceBusClient sb, CancellationToken ct) =>
{
await using var sender = sb.CreateSender("orders");
await sender.SendMessageAsync(new ServiceBusMessage(BinaryData.FromObjectAsJson(req)) { MessageId = req.OrderId.ToString() }, ct);
return Results.Accepted();
});
app.Run();
public sealed record OrderRequest(Guid OrderId, decimal Total);
// Orders.Api/appsettings.json: tune the client integration without code
{
"Aspire": {
"Azure": {
"Messaging": {
"ServiceBus": { "DisableTracing": false, "ClientOptions": { "RetryOptions": { "MaxRetries": 5 } } }
}
}
}
}
Aspire.Hosting.* in the AppHost, Aspire.* in services.ConfigureInfrastructure, review aspire publish output in pull requests like any IaC, and back it with Azure Policy.GetConnectionString where needed, and add tracing yourself.Integrations shine when you have many services and want one way to connect to each resource: the same health checks, the same telemetry, the same identity model. For a single service the value is smaller, and I'm happy to use the SDK directly.
The generated Bicep is infrastructure as code, and I treat it that way: aspire publish output is reviewed in pull requests, versioned, and deployed by the pipeline rather than from a laptop. Where an organisation already standardises on Terraform or a platform team owns shared infrastructure (networking, Key Vault, the Container Apps environment), I keep that IaC as the source of truth and have the AppHost reference those resources as existing, so Aspire only owns the app-level pieces. On emulators: they're for the inner loop. Throttling, quotas, RBAC, private endpoints and latency only behave realistically against real Azure resources, so I run the integration suite against a real test environment in CI before a release.
| Approach | When it fits | Cost | When not to |
|---|---|---|---|
| Client integration | Many services, standard usage | Defaults to learn; package updates | Exotic SDK configuration |
| Plain SDK + GetConnectionString | Full control, unusual options | Wire health and tracing yourself | Large fleets needing consistency |
| Emulator locally | Fast, free inner loop | Feature gaps; unrealistic limits and auth | Testing behaviour only the real service has |
| Real dev or test resources | No emulator, realistic tests | Azure spend, access management | Every developer by default |
| Aspire-generated Bicep | App-level resources owned by the team | Review discipline | Shared platform infrastructure owned elsewhere |
| Separate Terraform/Bicep + AsExisting | Platform team owns infrastructure | Two places to look | Small teams owning everything |
Managed identity gives the app an Entra ID identity that Azure manages, so there is no secret to store or rotate. In code, Azure.Identity gets tokens: DefaultAzureCredential tries managed identity in Azure and the developer's az login or Visual Studio sign-in locally. Then:
AddAzureKeyVault.BlobServiceClient with the credential.CREATE USER [app-name] FROM EXTERNAL PROVIDER, add it to database roles, and use Authentication=Active Directory Default in the connection string.Use a user-assigned identity when several apps share access or it must survive redeploys. The trade-off is setup effort in RBAC and SQL users in exchange for no secrets at all.
They solve different problems:
All of them deliver at least once, so consumers must deduplicate. The trade-off is features versus cost and throughput: Service Bus gives the richest guarantees, Event Hubs the highest throughput, Queue Storage the lowest price.
Service defaults is a shared class library that each service calls with builder.AddServiceDefaults(). It is code you own, generated by the template:
HttpClient and runtime instrumentation, exported over OTLP when OTEL_EXPORTER_OTLP_ENDPOINT is set.self check; MapDefaultEndpoints() maps /health (readiness) and /alive (liveness), only in Development by default.HttpClient gets service discovery and the standard resilience handler (timeouts, retries, circuit breaker).It is a starting baseline, not a finished production configuration. Before production each service tunes retries for non-idempotent calls, decides how health endpoints are exposed, registers its own ActivitySource and Meter names, and sets sampling.
How to tell it (STAR)
**S:** Our dev subscription bill jumped to [three times] normal because every developer's Aspire AppHost was provisioning its own Azure resources, some on Premium SKUs. **T:** I was asked to get costs back under control without slowing anyone down. **A:** I mapped the resource groups to the AppHost model, switched Service Bus and Storage to emulators, pointed Key Vault and OpenAI at shared existing resources, pinned SKUs in the generated Bicep and added tagging policy with a nightly clean-up. **R:** The bill fell by [about 70%] the next month, and local start-up got faster because emulators start in seconds.
Last updated 23 Nov 2026.