# AzureServiceBusExtensions Methods

- Package: [Aspire.Hosting.Azure.ServiceBus](/reference/api/csharp/aspire.hosting.azure.servicebus.md)
- Type: [AzureServiceBusExtensions](/reference/api/csharp/aspire.hosting.azure.servicebus/azureservicebusextensions.md)
- Kind: `Methods`
- Members: `16`

Provides extension methods for adding the Azure Service Bus resources to the application model.

## AddAzureServiceBus(IDistributedApplicationBuilder, string)

- Name: `AddAzureServiceBus(IDistributedApplicationBuilder, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureServiceBusResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs#L46-L143)

Adds an Azure Service Bus Namespace resource to the application model. This resource can be used to create queue, topic, and subscription resources.

```csharp
public static class AzureServiceBusExtensions
{
    public static IResourceBuilder<AzureServiceBusResource> AddAzureServiceBus(
        this IDistributedApplicationBuilder builder,
        string name)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The builder for the distributed application.
- `name` (`string`)
  The name of the resource.

## Returns

`IResourceBuilder<AzureServiceBusResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

By default references to the Azure Service Bus resource will be assigned the following roles: - `ServiceBusBuiltInRole.AzureServiceBusDataOwner` These can be replaced by calling [AzureServiceBusExtensions.WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<AzureServiceBusResource>, ServiceBusBuiltInRole[])](/reference/api/csharp/aspire.hosting.azure.servicebus/azureservicebusextensions/methods.md#withroleassignments-iresourcebuilder-t-iresourcebuilder-azureservicebusresource-servicebusbuiltinrole).

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddQueue(IResourceBuilder<AzureServiceBusResource>, string)

> **Obsolete:** This method is obsolete because it has the wrong return type and will be removed in a future version. Use AddServiceBusQueue instead to add an Azure Service Bus Queue.

- Name: `AddQueue(IResourceBuilder<AzureServiceBusResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureServiceBusResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs#L157-L162)

Adds an Azure Service Bus Queue resource to the application model.

```csharp
public static class AzureServiceBusExtensions
{
    public static IResourceBuilder<AzureServiceBusResource> AddQueue(
        this IResourceBuilder<AzureServiceBusResource> builder,
        string name)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureServiceBusResource>`)
  The Azure Service Bus resource builder.
- `name` (`string`)
  The name of the queue resource.

## Returns

`IResourceBuilder<AzureServiceBusResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

This method is not available in polyglot app hosts. Use [AzureServiceBusExtensions.AddServiceBusQueue(IResourceBuilder<AzureServiceBusResource>, string, string?)](/reference/api/csharp/aspire.hosting.azure.servicebus/azureservicebusextensions/methods.md#addservicebusqueue-iresourcebuilder-azureservicebusresource-string-string) instead.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## AddServiceBusQueue(IResourceBuilder<AzureServiceBusResource>, string, string?)

- Name: `AddServiceBusQueue(IResourceBuilder<AzureServiceBusResource>, string, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureServiceBusQueueResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs#L176-L185)

Adds an Azure Service Bus Queue resource to the application model.

```csharp
public static class AzureServiceBusExtensions
{
    public static IResourceBuilder<AzureServiceBusQueueResource> AddServiceBusQueue(
        this IResourceBuilder<AzureServiceBusResource> builder,
        string name,
        string? queueName = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureServiceBusResource>`)
  The Azure Service Bus resource builder.
- `name` (`string`)
  The name of the queue resource.
- `queueName` (`string?`) `optional`
  The name of the Service Bus Queue. If not provided, this defaults to the same value as `name`.

## Returns

`IResourceBuilder<AzureServiceBusQueueResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddServiceBusSubscription(IResourceBuilder<AzureServiceBusTopicResource>, string, string?)

- Name: `AddServiceBusSubscription(IResourceBuilder<AzureServiceBusTopicResource>, string, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureServiceBusSubscriptionResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs#L333-L342)

Adds an Azure Service Bus Subscription resource to the application model.

```csharp
public static class AzureServiceBusExtensions
{
    public static IResourceBuilder<AzureServiceBusSubscriptionResource> AddServiceBusSubscription(
        this IResourceBuilder<AzureServiceBusTopicResource> builder,
        string name,
        string? subscriptionName = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureServiceBusTopicResource>`)
  The Azure Service Bus Topic resource builder.
- `name` (`string`)
  The name of the subscription resource.
- `subscriptionName` (`string?`) `optional`
  The name of the Service Bus Subscription. If not provided, this defaults to the same value as `name`.

## Returns

`IResourceBuilder<AzureServiceBusSubscriptionResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddServiceBusTopic(IResourceBuilder<AzureServiceBusResource>, string, string?)

- Name: `AddServiceBusTopic(IResourceBuilder<AzureServiceBusResource>, string, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureServiceBusTopicResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs#L261-L270)

Adds an Azure Service Bus Topic resource to the application model.

```csharp
public static class AzureServiceBusExtensions
{
    public static IResourceBuilder<AzureServiceBusTopicResource> AddServiceBusTopic(
        this IResourceBuilder<AzureServiceBusResource> builder,
        string name,
        string? topicName = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureServiceBusResource>`)
  The Azure Service Bus resource builder.
- `name` (`string`)
  The name of the topic resource.
- `topicName` (`string?`) `optional`
  The name of the Service Bus Topic. If not provided, this defaults to the same value as `name`.

## Returns

`IResourceBuilder<AzureServiceBusTopicResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddSubscription(IResourceBuilder<AzureServiceBusResource>, string, string)

> **Obsolete:** This method is obsolete and will be removed in a future version. Use AddServiceBusSubscription instead to add an Azure Service Bus Subscription to a Topic.

- Name: `AddSubscription(IResourceBuilder<AzureServiceBusResource>, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureServiceBusResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs#L303-L319)

Adds an Azure Service Bus Subscription resource to the application model.

```csharp
public static class AzureServiceBusExtensions
{
    public static IResourceBuilder<AzureServiceBusResource> AddSubscription(
        this IResourceBuilder<AzureServiceBusResource> builder,
        string topicName,
        string subscriptionName)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureServiceBusResource>`)
  The Azure Service Bus resource builder.
- `topicName` (`string`)
  The name of the topic resource.
- `subscriptionName` (`string`)
  The name of the subscription.

## Returns

`IResourceBuilder<AzureServiceBusResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

This method is not available in polyglot app hosts. Use [AzureServiceBusExtensions.AddServiceBusSubscription(IResourceBuilder<AzureServiceBusTopicResource>, string, string?)](/reference/api/csharp/aspire.hosting.azure.servicebus/azureservicebusextensions/methods.md#addservicebussubscription-iresourcebuilder-azureservicebustopicresource-string-string) instead.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## AddTopic(IResourceBuilder<AzureServiceBusResource>, string)

> **Obsolete:** This method is obsolete because it has the wrong return type and will be removed in a future version. Use AddServiceBusTopic instead to add an Azure Service Bus Topic.

- Name: `AddTopic(IResourceBuilder<AzureServiceBusResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureServiceBusResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs#L216-L221)

Adds an Azure Service Bus Topic resource to the application model.

```csharp
public static class AzureServiceBusExtensions
{
    public static IResourceBuilder<AzureServiceBusResource> AddTopic(
        this IResourceBuilder<AzureServiceBusResource> builder,
        string name)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureServiceBusResource>`)
  The Azure Service Bus resource builder.
- `name` (`string`)
  The name of the topic resource.

## Remarks

This method is not available in polyglot app hosts. Use [AzureServiceBusExtensions.AddServiceBusTopic(IResourceBuilder<AzureServiceBusResource>, string, string?)](/reference/api/csharp/aspire.hosting.azure.servicebus/azureservicebusextensions/methods.md#addservicebustopic-iresourcebuilder-azureservicebusresource-string-string) instead.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## AddTopic(IResourceBuilder<AzureServiceBusResource>, string, string[])

> **Obsolete:** This method is obsolete because it has the wrong return type and will be removed in a future version. Use AddServiceBusTopic and AddServiceBusSubscription instead to add an Azure Service Bus Topic and Subscriptions.

- Name: `AddTopic(IResourceBuilder<AzureServiceBusResource>, string, string[])`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureServiceBusResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs#L235-L247)

Adds an Azure Service Bus Topic resource to the application model.

```csharp
public static class AzureServiceBusExtensions
{
    public static IResourceBuilder<AzureServiceBusResource> AddTopic(
        this IResourceBuilder<AzureServiceBusResource> builder,
        string name,
        string[] subscriptions)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureServiceBusResource>`)
  The Azure Service Bus resource builder.
- `name` (`string`)
  The name of the topic resource.
- `subscriptions` (`string[]`)
  The name of the subscriptions.

## Remarks

This method is not available in polyglot app hosts. Use [AzureServiceBusExtensions.AddServiceBusTopic(IResourceBuilder<AzureServiceBusResource>, string, string?)](/reference/api/csharp/aspire.hosting.azure.servicebus/azureservicebusextensions/methods.md#addservicebustopic-iresourcebuilder-azureservicebusresource-string-string) and [AzureServiceBusExtensions.AddServiceBusSubscription(IResourceBuilder<AzureServiceBusTopicResource>, string, string?)](/reference/api/csharp/aspire.hosting.azure.servicebus/azureservicebusextensions/methods.md#addservicebussubscription-iresourcebuilder-azureservicebustopicresource-string-string) instead.

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## RunAsEmulator(IResourceBuilder<AzureServiceBusResource>, Action<IResourceBuilder<AzureServiceBusEmulatorResource>>)

- Name: `RunAsEmulator(IResourceBuilder<AzureServiceBusResource>, Action<IResourceBuilder<AzureServiceBusEmulatorResource>>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureServiceBusResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs#L394-L512)

Configures an Azure Service Bus resource to be emulated. This resource requires an [AzureServiceBusResource](/reference/api/csharp/aspire.hosting.azure.servicebus/azureservicebusresource.md) to be added to the application model.

```csharp
public static class AzureServiceBusExtensions
{
    public static IResourceBuilder<AzureServiceBusResource> RunAsEmulator(
        this IResourceBuilder<AzureServiceBusResource> builder,
        Action<IResourceBuilder<AzureServiceBusEmulatorResource>>? configureContainer = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureServiceBusResource>`)
- `configureContainer` (`Action<IResourceBuilder<AzureServiceBusEmulatorResource>>`) `optional`

## Remarks

This version of the package defaults to the tag of the / container image. The Azure Service Bus resource builder. Callback that exposes underlying container used for emulation to allow for customization. A reference to the `ApplicationModel.IResourceBuilder`1`. The resource builder. The following example creates an Azure Service Bus resource that runs locally is an emulator and referencing that resource in a .NET project.

```csharp
var builder = DistributedApplication.CreateBuilder(args);

var serviceBus = builder.AddAzureServiceBus("myservicebus")
   .RunAsEmulator()
   .AddQueue("queue");

builder.AddProject<Projects.InventoryService>()
       .WithReference(serviceBus);

builder.Build().Run();
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithConfiguration(IResourceBuilder<AzureServiceBusEmulatorResource>, Action<JsonNode>)

- Name: `WithConfiguration(IResourceBuilder<AzureServiceBusEmulatorResource>, Action<JsonNode>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureServiceBusEmulatorResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs#L557-L562)

Alters the JSON configuration document used by the emulator.

```csharp
public static class AzureServiceBusExtensions
{
    public static IResourceBuilder<AzureServiceBusEmulatorResource> WithConfiguration(
        this IResourceBuilder<AzureServiceBusEmulatorResource> builder,
        Action<JsonNode> configJson)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureServiceBusEmulatorResource>`)
  The builder for the [AzureServiceBusEmulatorResource](/reference/api/csharp/aspire.hosting.azure.servicebus/azureservicebusemulatorresource.md).
- `configJson` (`Action<JsonNode>`)
  A callback to update the JSON object representation of the configuration.

## Returns

`IResourceBuilder<AzureServiceBusEmulatorResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

This method is not available in polyglot app hosts. Use [AzureServiceBusExtensions.WithConfigurationFile(IResourceBuilder<AzureServiceBusEmulatorResource>, string)](/reference/api/csharp/aspire.hosting.azure.servicebus/azureservicebusextensions/methods.md#withconfigurationfile-iresourcebuilder-azureservicebusemulatorresource-string) instead to provide a configuration file. Here is an example of how to configure the emulator to use a different logging mechanism:

```csharp
var builder = DistributedApplication.CreateBuilder(args);

builder.AddAzureServiceBus("servicebusns")
       .RunAsEmulator(configure => configure
           .WithConfiguration(document =>
           {
               document["UserConfig"]!["Logging"] = new JsonObject { ["Type"] = "Console" };
           });
       );
```

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## WithConfigurationFile(IResourceBuilder<AzureServiceBusEmulatorResource>, string)

- Name: `WithConfigurationFile(IResourceBuilder<AzureServiceBusEmulatorResource>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureServiceBusEmulatorResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs#L525-L528)

Copies the configuration file into an Azure Service Bus emulator resource.

```csharp
public static class AzureServiceBusExtensions
{
    public static IResourceBuilder<AzureServiceBusEmulatorResource> WithConfigurationFile(
        this IResourceBuilder<AzureServiceBusEmulatorResource> builder,
        string path)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureServiceBusEmulatorResource>`)
  The builder for the [AzureServiceBusEmulatorResource](/reference/api/csharp/aspire.hosting.azure.servicebus/azureservicebusemulatorresource.md).
- `path` (`string`)
  Path to the file on the AppHost where the emulator configuration is located.

## Returns

`IResourceBuilder<AzureServiceBusEmulatorResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithHostPort(IResourceBuilder<AzureServiceBusEmulatorResource>, int?)

- Name: `WithHostPort(IResourceBuilder<AzureServiceBusEmulatorResource>, int?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureServiceBusEmulatorResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs#L575-L580)

Configures the host port for the Azure Service Bus emulator is exposed on instead of using randomly assigned port.

```csharp
public static class AzureServiceBusExtensions
{
    public static IResourceBuilder<AzureServiceBusEmulatorResource> WithHostPort(
        this IResourceBuilder<AzureServiceBusEmulatorResource> builder,
        int? port)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureServiceBusEmulatorResource>`)
  Builder for the Azure Service Bus emulator container
- `port` (`int?`)
  The port to bind on the host. If `null` is used, a random port will be assigned.

## Returns

`IResourceBuilder<AzureServiceBusEmulatorResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithProperties(IResourceBuilder<AzureServiceBusQueueResource>, Action<AzureServiceBusQueueResource>)

- Name: `WithProperties(IResourceBuilder<AzureServiceBusQueueResource>, Action<AzureServiceBusQueueResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureServiceBusQueueResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs)

Allows setting the properties of an Azure Service Bus Queue resource.

```csharp
public static class AzureServiceBusExtensions
{
    public static IResourceBuilder<AzureServiceBusQueueResource> WithProperties(
        this IResourceBuilder<AzureServiceBusQueueResource> builder,
        Action<AzureServiceBusQueueResource> configure)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureServiceBusQueueResource>`)
  The Azure Service Bus Queue resource builder.
- `configure` (`Action<AzureServiceBusQueueResource>`)
  A method that can be used for customizing the [AzureServiceBusQueueResource](/reference/api/csharp/aspire.hosting.azure.servicebus/azureservicebusqueueresource.md).

## Returns

`IResourceBuilder<AzureServiceBusQueueResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithProperties(IResourceBuilder<AzureServiceBusTopicResource>, Action<AzureServiceBusTopicResource>)

- Name: `WithProperties(IResourceBuilder<AzureServiceBusTopicResource>, Action<AzureServiceBusTopicResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureServiceBusTopicResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs)

Allows setting the properties of an Azure Service Bus Topic resource.

```csharp
public static class AzureServiceBusExtensions
{
    public static IResourceBuilder<AzureServiceBusTopicResource> WithProperties(
        this IResourceBuilder<AzureServiceBusTopicResource> builder,
        Action<AzureServiceBusTopicResource> configure)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureServiceBusTopicResource>`)
  The Azure Service Bus Topic resource builder.
- `configure` (`Action<AzureServiceBusTopicResource>`)
  A method that can be used for customizing the [AzureServiceBusTopicResource](/reference/api/csharp/aspire.hosting.azure.servicebus/azureservicebustopicresource.md).

## Returns

`IResourceBuilder<AzureServiceBusTopicResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithProperties(IResourceBuilder<AzureServiceBusSubscriptionResource>, Action<AzureServiceBusSubscriptionResource>)

- Name: `WithProperties(IResourceBuilder<AzureServiceBusSubscriptionResource>, Action<AzureServiceBusSubscriptionResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureServiceBusSubscriptionResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs)

Allows setting the properties of an Azure Service Bus Subscription resource.

```csharp
public static class AzureServiceBusExtensions
{
    public static IResourceBuilder<AzureServiceBusSubscriptionResource> WithProperties(
        this IResourceBuilder<AzureServiceBusSubscriptionResource> builder,
        Action<AzureServiceBusSubscriptionResource> configure)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureServiceBusSubscriptionResource>`)
  The Azure Service Bus Subscription resource builder.
- `configure` (`Action<AzureServiceBusSubscriptionResource>`)
  A method that can be used for customizing the [AzureServiceBusSubscriptionResource](/reference/api/csharp/aspire.hosting.azure.servicebus/azureservicebussubscriptionresource.md).

## Returns

`IResourceBuilder<AzureServiceBusSubscriptionResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<AzureServiceBusResource>, ServiceBusBuiltInRole[])

- Name: `WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<AzureServiceBusResource>, ServiceBusBuiltInRole[])`
- Modifiers: `extension`
- Returns: `IResourceBuilder<T>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusExtensions.cs)

Assigns the specified roles to the given resource, granting it the necessary permissions on the target Azure Service Bus namespace. This replaces the default role assignments for the resource.

```csharp
public static class AzureServiceBusExtensions
{
    public static IResourceBuilder<T> WithRoleAssignments<T>(
        this IResourceBuilder<T> builder,
        IResourceBuilder<AzureServiceBusResource> target,
        params ServiceBusBuiltInRole[] roles)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<T>`)
  The resource to which the specified roles will be assigned.
- `target` (`IResourceBuilder<AzureServiceBusResource>`)
  The target Azure Service Bus namespace.
- `roles` (`ServiceBusBuiltInRole[]`)
  The built-in Service Bus roles to be assigned.

## Returns

`IResourceBuilder<T>` -- The updated `ApplicationModel.IResourceBuilder`1` with the applied role assignments.

## Remarks

This overload is not available in polyglot app hosts. Use [AzureServiceBusExtensions.WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<AzureServiceBusResource>, ServiceBusBuiltInRole[])](/reference/api/csharp/aspire.hosting.azure.servicebus/azureservicebusextensions/methods.md#withroleassignments-iresourcebuilder-t-iresourcebuilder-azureservicebusresource-servicebusbuiltinrole) instead.

```csharp
var builder = DistributedApplication.CreateBuilder(args);

var sb = builder.AddAzureServiceBus("bus");

var api = builder.AddProject<Projects.Api>("api")
  .WithRoleAssignments(sb, ServiceBusBuiltInRole.AzureServiceBusDataSender)
  .WithReference(sb);
```

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.
