Skip to main content
Table of Contents

Class AzureServiceBusServiceCollectionExtensions

Namespace
Microsoft.Extensions.DependencyInjection
Assembly
Stratara.Outbox.AzureServiceBus.dll

Service-collection extensions for wiring Azure Service Bus as the Stratara IMessageBus implementation.

public static class AzureServiceBusServiceCollectionExtensions
Inheritance
AzureServiceBusServiceCollectionExtensions
Inherited Members

Methods

AddAzureServiceBus(IServiceCollection, string)

Registers the Stratara Azure Service Bus message bus using a SAS-token connection string. The connection string typically lives in ConnectionStrings:ServiceBus and is suitable for local development. For production, prefer AddAzureServiceBusWithManagedIdentity(IServiceCollection, string, TokenCredential?) so the broker is reached via Azure-AD-issued tokens instead of long-lived SAS keys.

public static IServiceCollection AddAzureServiceBus(this IServiceCollection services, string connectionString)

Parameters

services IServiceCollection

The service collection.

connectionString string

Azure Service Bus connection string (SAS).

Returns

IServiceCollection

The same service collection for chaining.

Examples

Replaces the RabbitMQ IMessageBus a worker composite may already have wired — one transport per host, and the explicit call wins:

services.AddAzureServiceBus(configuration.GetConnectionString("servicebus")!);

Exceptions

ArgumentException

connectionString is null or empty.

AddAzureServiceBusWithManagedIdentity(IServiceCollection, string, TokenCredential?)

Registers the Stratara Azure Service Bus message bus using Azure-AD authentication (Managed Identity by default, or a caller-supplied TokenCredential). Preferred path for production — SAS tokens leak through configuration files and secret stores with a much wider exposure surface than AAD-issued tokens; Managed Identity also rotates and revokes automatically (Round-3-Audit Finding R3-Sec-007).

public static IServiceCollection AddAzureServiceBusWithManagedIdentity(this IServiceCollection services, string fullyQualifiedNamespace, TokenCredential? credential = null)

Parameters

services IServiceCollection

The service collection.

fullyQualifiedNamespace string

The Azure Service Bus namespace FQDN, e.g. my-bus.servicebus.windows.net.

credential TokenCredential

Optional TokenCredential; defaults to DefaultAzureCredential (Managed Identity → environment → CLI chain).

Returns

IServiceCollection

The same service collection for chaining.

Examples

Uses DefaultAzureCredential unless a credential is passed, so a host running with a managed identity needs no connection string:

services.AddAzureServiceBusWithManagedIdentity("my-namespace.servicebus.windows.net");

Exceptions

ArgumentException

fullyQualifiedNamespace is null or empty.