DKNet

Aspire.Hosting.ServiceBus

Hosting integration that adds the Azure Service Bus emulator as a resource inside a .NET Aspire AppHost.

✨ Why use it?

Reach for it when you want a message-driven workflow — queues and topics defined by a Service Bus emulator config file — running locally under Aspire’s orchestrator alongside the rest of your distributed application.

🚀 Quick Start

dotnet add package Aspire.Hosting.ServiceBus

Reference it from your AppHost project only — like other Aspire hosting integrations, it is consumed by the orchestrator project, not by the services being orchestrated.

The emulator container requires a SQL Server resource as its backing store and a JSON config file describing the emulator’s namespace/queue/topic topology (the same Config.json format the Azure Service Bus emulator itself expects):

using Aspire.Hosting.ServiceBus;

var builder = DistributedApplication.CreateBuilder(args);

var sql = builder.AddSqlServer("sql");

var serviceBus = builder.AddServiceBus(sql, configFilePath: "servicebus-config.json");

builder.AddProject<Projects.Api>("api")
    .WithReference(serviceBus);

builder.Build().Run();

AddServiceBus returns IResourceBuilder<ServiceBusResource>, so it composes with the rest of Aspire’s fluent builder API (WithReference, WithEnvironment, WaitFor, …) exactly like any other resource builder.

🧩 Features

AddServiceBus — register the emulator resource

public static IResourceBuilder<ServiceBusResource> AddServiceBus(
    this IDistributedApplicationBuilder builder,
    IResourceBuilder<SqlServerServerResource> sqlServer,
    string configFilePath,
    string name = "AzureBusSimulator")

One call wires up everything the emulator container needs:

ServiceBusResource — the resource type

ServiceBusResource is a sealed ContainerResource implementing IResourceWithConnectionString, so it works with any Aspire API that consumes connection-string resources (WithReference, health checks, …):

⚙️ Configuration reference

Parameter Required Default Effect
sqlServer yes — The SQL Server resource the emulator uses as its backing store; the emulator waits on it before starting.
configFilePath yes — Host path to the emulator’s Config.json (namespaces, queues, topics, subscriptions) — bind-mounted read-only into the container.
name no "AzureBusSimulator" The Aspire resource name for the emulator.

There is no fluent API on ServiceBusResource for declaring queues or topics in code — that topology is entirely the responsibility of the JSON file passed as configFilePath. The image registry, name, and tag (mcr.microsoft.com/azure-messaging/servicebus-emulator:latest) and both endpoint ports (5672, 5671) are fixed by the extension and are not configurable through parameters.

🧱 Where it fits

One AddServiceBus call adds the resource on the left and everything inside the boundary; you still supply the SQL Server resource and the config file:

Architecture diagram: the AppHost registers a ServiceBusResource whose SQL Server resource supplies the SQL_SERVER environment variable and is waited on, and whose Config.json is bind-mounted read-only; inside the boundary added by AddServiceBus the resource runs the mcr.microsoft.com emulator image at the latest tag, exposes the tcp 5672 and tcp2 5671 AMQP endpoints, and builds the UseDevelopmentEmulator connection string that is injected into a referencing API or worker project.

Aspire only provisions the transport; message handling still runs through DKNet.SlimBus.Extensions. Once you have wired WithReference(serviceBus) onto a downstream project, that project resolves the connection string the normal Aspire configuration way and hands it to SlimMessageBus’s own Azure Service Bus provider (SlimMessageBus.Host.AzureServiceBus) — using the emulator locally and a real Azure Service Bus connection string in higher environments, with no change to handler code.

⚠️ Gotchas & limits