Share via


AzureWebPubSubExtensions.WithRoleAssignments<T> Method

Definition

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

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<T> WithRoleAssignments<T>(this Aspire.Hosting.ApplicationModel.IResourceBuilder<T> builder, Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.AzureWebPubSubResource> target, params Azure.Provisioning.WebPubSub.WebPubSubBuiltInRole[] roles) where T : Aspire.Hosting.ApplicationModel.IResource;
static member WithRoleAssignments : Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.IResource)> * Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.AzureWebPubSubResource> * Azure.Provisioning.WebPubSub.WebPubSubBuiltInRole[] -> Aspire.Hosting.ApplicationModel.IResourceBuilder<'T (requires 'T :> Aspire.Hosting.ApplicationModel.IResource)> (requires 'T :> Aspire.Hosting.ApplicationModel.IResource)
<Extension()>
Public Function WithRoleAssignments(Of T As IResource) (builder As IResourceBuilder(Of T), target As IResourceBuilder(Of AzureWebPubSubResource), ParamArray roles As WebPubSubBuiltInRole()) As IResourceBuilder(Of T)

Type Parameters

T

Parameters

builder
IResourceBuilder<T>

The resource to which the specified roles will be assigned.

target
IResourceBuilder<AzureWebPubSubResource>

The target Azure Web PubSub resource.

roles
WebPubSubBuiltInRole[]

The built-in Web PubSub roles to be assigned.

Returns

The updated IResourceBuilder<T> with the applied role assignments.

Examples

Assigns the WebPubSubServiceReader role to the 'Projects.Api' project.

var builder = DistributedApplication.CreateBuilder(args);

var webPubSub = builder.AddAzureWebPubSub("webPubSub");

var api = builder.AddProject<Projects.Api>("api")
  .WithRoleAssignments(webPubSub, WebPubSubBuiltInRole.WebPubSubServiceReader)
  .WithReference(webPubSub);

Applies to