📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

What are Aspire integrations? Explain the difference between hosting and client integrations, what a client integration adds beyond the plain SDK, and how you add Azure resources such as Service Bus and Storage, run them locally or provision them in Azure, and connect to ones that already exist.

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.

Mid-Level Theory Intermediate azure-service-bus azure-storage bicep cloud-native dotnet-aspire integrations

🎯 Key points

  • Hosting integrations (Aspire.Hosting.*) live in the AppHost and model or run a resource; client integrations (Aspire.*) live in the service and connect to it
  • A client integration registers the SDK client in DI from a named connection string and adds health checks, OpenTelemetry tracing and metrics, and sensible retries
  • Client settings are configurable under Aspire:{Provider}:{Component} sections or via a delegate; DisableHealthChecks and DisableTracing switch features off
  • Azure hosting integrations (AddAzureServiceBus, AddAzureStorage, AddAzureKeyVault) generate Bicep and connect with managed identity, not keys
  • Locally you choose: RunAsEmulator() for Service Bus, Storage (Azurite) and Cosmos DB, or real provisioning using Azure:SubscriptionId and Azure:Location in user secrets
  • AsExisting / existing-resource APIs point at resources owned by another team; ConfigureInfrastructure customises the generated Bicep (SKUs, tags, network rules)
  • You don't have to use client integrations: plain SDK registration with GetConnectionString still works
  • Community Toolkit integrations exist but carry their own support and quality risks

⏱ 30-second answer

Integrations come in two halves:

  • Hosting integrations (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.
  • Client integrations (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.

🗣 Full answer (senior)

How I would answer this in an interview

"An integration is a pair of NuGet packages. The hosting side, Aspire.Hosting.Redis or Aspire.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, like Aspire.StackExchange.Redis or Aspire.Azure.Messaging.ServiceBus, is referenced by the service. One call such as builder.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 during aspire run, using Azure:SubscriptionId and Azure:Location from 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 with ConfigureInfrastructure.

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 with GetConnectionString. Integrations buy consistency across many services, but the team still has to know what defaults they're applying."


Hosting vs client

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")

Azure resources: local options

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

Production example

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].

🔍 What the interviewer is checking

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

  • Explains hosting vs client clearly.
  • Lists what client integrations register: DI, health checks, telemetry, retries.
  • Knows emulator vs provisioning vs existing resources.
  • Mentions managed identity and customising Bicep.

Red flags

  • Thinks integrations are required for Aspire to work.
  • Uses access keys in production by default.
  • Has never looked at the generated infrastructure.

📚 Learn in depth

1. Two packages, two processes

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

2. What a client integration registers

  1. Reads ConnectionStrings:{name} (a full connection string, or just an endpoint/namespace for Azure resources, combined with DefaultAzureCredential).
  2. Binds settings from Aspire:{Provider}:{Component} (e.g. Aspire:Azure:Messaging:ServiceBus) and any delegate you pass.
  3. Registers the client with the recommended lifetime (usually a singleton), optionally keyed (AddKeyedRedisClient).
  4. Adds a health check, unless DisableHealthChecks is set.
  5. Enables the SDK's ActivitySource and Meter for OpenTelemetry, unless disabled.

3. Azure hosting and Bicep generation

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.

4. Local provisioning

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.

5. Choosing a model per resource

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

6. Beyond Microsoft packages

The Aspire Community Toolkit adds integrations (for example extra databases and tools). Treat them like any third-party dependency: check maintenance, versions and licence.

Try it yourself

  1. Add Aspire.Hosting.Azure.ServiceBus to an AppHost, create a queue, call RunAsEmulator() and send a message from an API using the client integration.
  2. Open the trace in the dashboard and find the producer and consumer spans.
  3. Remove RunAsEmulator(), set Azure:SubscriptionId and Azure:Location in user secrets, and watch the resource group appear in the portal.
  4. Use ConfigureInfrastructure to set a tag, run aspire publish, and find it in the generated Bicep.
  5. Register a second ServiceBusClient without the integration and compare what appears in the dashboard.

💻 Code

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 } } }
      }
    }
  }
}

⚠ Common mistakes

  • Mistake: Adding the hosting package to the service or the client package to the AppHost. Why it is wrong: The AppHost models resources and the service consumes them; mixing them up pulls in the wrong dependencies and nothing gets registered. Instead: Aspire.Hosting.* in the AppHost, Aspire.* in services.
  • Mistake: Using connection strings with shared access keys for Azure resources in deployed apps. Why it is wrong: Keys are long-lived secrets that leak and are hard to rotate. Instead: Let the generated role assignments and managed identity do it; keep keys only for emulators.
  • Mistake: Provisioning real Azure resources from every developer machine without a plan. Why it is wrong: Each developer creates resource groups that cost money and are forgotten. Instead: Prefer emulators, use a shared dev subscription with budgets, and clean up with policy or tags.
  • Mistake: Deploying the generated Bicep without reviewing or customising it. Why it is wrong: Defaults may leave public network access on, pick SKUs you don't want, or miss tags, which creates security and cost problems against your Essential Eight and landing-zone standards. Instead: Customise with ConfigureInfrastructure, review aspire publish output in pull requests like any IaC, and back it with Azure Policy.
  • Mistake: Assuming the emulator behaves exactly like the cloud service. Why it is wrong: Emulators have quotas, missing features and different auth, so throttling and RBAC bugs appear only in Azure. Instead: Run integration tests against real resources in CI before release.
  • Mistake: Believing you must use a client integration. Why it is wrong: Some teams need full SDK control and the integration hides it. Instead: Register the SDK directly from GetConnectionString where needed, and add tracing yourself.

🏛 Senior insight: trade-offs

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

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions managed identity for Azure resources Why: Checks DefaultAzureCredential and RBAC set-up
    How to answer

    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:

    • Key Vault: grant Key Vault Secrets User and use AddAzureKeyVault.
    • Blob Storage: grant Storage Blob Data Contributor and create BlobServiceClient with the credential.
    • Azure SQL: 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.

  2. When: Candidate uses Service Bus as the example Why: Checks choosing between Azure messaging services
    How to answer

    They solve different problems:

    • Blob Storage stores files and large payloads; it is not a messaging service.
    • Queue Storage is a cheap, simple queue (64 KiB messages, no ordering, no dead-letter queue).
    • Service Bus is the enterprise broker for commands and business messages: queues, topics, sessions for ordering, dead-lettering, duplicate detection, transactions.
    • Event Grid pushes discrete events ("a blob was created", "an order shipped") to subscribers, with retries.
    • Event Hubs ingests streams of millions of events into partitions that consumers read at their own pace.

    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.

  3. When: Candidate says integrations add health checks and telemetry Why: Checks how service defaults and integrations fit together
    How to answer

    Service defaults is a shared class library that each service calls with builder.AddServiceDefaults(). It is code you own, generated by the template:

    • OpenTelemetry: logs, traces and metrics with ASP.NET Core, HttpClient and runtime instrumentation, exported over OTLP when OTEL_EXPORTER_OTLP_ENDPOINT is set.
    • Health checks: a self check; MapDefaultEndpoints() maps /health (readiness) and /alive (liveness), only in Development by default.
    • Every 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.

🛠 Real-world problems: how you handle them

Developer-provisioned Azure resources tripled the dev subscription bill
Situation
[Twelve developers] on a .NET 10 Aspire solution with Service Bus, Storage, Key Vault and Azure OpenAI. The AppHost provisioned real Azure resources for every developer in a shared dev subscription.
Signals
A Cost Management budget alert at [150%] mid-month; [40-plus] resource groups named after AppHosts and machines; some Service Bus namespaces on Premium from a copied sample.
Investigation
Grouped costs by resource group and tag in Cost Management; matched resource groups to developers; read the AppHost to see which resources had no emulator option; checked generated Bicep for SKUs.
Resolution
Immediate: deleted stale resource groups and downgraded SKUs. Real fix: `RunAsEmulator()` for Service Bus and Storage, one shared existing Key Vault and OpenAI deployment referenced with existing-resource parameters, and `ConfigureInfrastructure` to pin Standard SKUs and add owner tags.
Prevention
Azure Policy requiring owner and expiry tags in the dev subscription, a nightly clean-up job for expired resource groups, budgets per team, and a pull request check on `aspire publish` output for SKU changes.

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.

↩ Usually asked after

More in .NET Aspire

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me