Skip to content
DocsTry Aspire
DocsTry

AzureWebPubSubExtensions Methods

ClassMethods6 members
Provides extension methods for adding the Azure Web PubSub resources to the application model.
AddAzureWebPubSub(IDistributedApplicationBuilder, string)Section titled AddAzureWebPubSub(IDistributedApplicationBuilder, string)extensionIResourceBuilder<AzureWebPubSubResource>
Adds an Azure Web PubSub resource to the application model. Change sku: WithParameter("sku", "Standard_S1") Change capacity: WithParameter("capacity", 2)
public static class AzureWebPubSubExtensions
{
public static IResourceBuilder<AzureWebPubSubResource> AddAzureWebPubSub(
this IDistributedApplicationBuilder builder,
string name)
{
// ...
}
}
builderIDistributedApplicationBuilderThe Hosting.IDistributedApplicationBuilder.
namestringThe name of the resource. This name will be used as the connection string name when referenced in a dependency.
IResourceBuilder<AzureWebPubSubResource>A reference to the ApplicationModel.IResourceBuilder`1.
By default references to the Azure Web PubSub resource will be assigned the following roles: - WebPubSubBuiltInRole.WebPubSubServiceOwner These can be replaced by calling AzureWebPubSubExtensions.WithRoleAssignments.
AddEventHandler(IResourceBuilder<AzureWebPubSubHubResource>, ExpressionInterpolatedStringHandler, string, string[]?, UpstreamAuthSettings?)Section titled AddEventHandler(IResourceBuilder<AzureWebPubSubHubResource>, ExpressionInterpolatedStringHandler, string, string[]?, UpstreamAuthSettings?)extensionIResourceBuilder<AzureWebPubSubHubResource>
Add event handler setting with expression
public static class AzureWebPubSubExtensions
{
public static IResourceBuilder<AzureWebPubSubHubResource> AddEventHandler(
this IResourceBuilder<AzureWebPubSubHubResource> builder,
ExpressionInterpolatedStringHandler urlTemplateExpression,
string userEventPattern = "*",
string[]? systemEvents = null,
UpstreamAuthSettings? authSettings = null)
{
// ...
}
}
builderIResourceBuilder<AzureWebPubSubHubResource>The builder for a Web PubSub hub.
urlTemplateExpressionExpressionInterpolatedStringHandlerThe expression to evaluate the URL template configured for the event handler.
userEventPatternstringoptionalThe user event pattern for the event handler.
systemEventsstring[]?optionalThe system events for the event handler.
authSettingsUpstreamAuthSettings?optionalThe auth settings configured for the event handler.
This overload is not available in polyglot app hosts. Configure Web PubSub event handlers without auth settings in polyglot app hosts.
AddEventHandler(IResourceBuilder<AzureWebPubSubHubResource>, ReferenceExpression, string, string[]?, UpstreamAuthSettings?)Section titled AddEventHandler(IResourceBuilder<AzureWebPubSubHubResource>, ReferenceExpression, string, string[]?, UpstreamAuthSettings?)extensionIResourceBuilder<AzureWebPubSubHubResource>
Add event handler setting with expression
public static class AzureWebPubSubExtensions
{
public static IResourceBuilder<AzureWebPubSubHubResource> AddEventHandler(
this IResourceBuilder<AzureWebPubSubHubResource> builder,
ReferenceExpression urlExpression,
string userEventPattern = "*",
string[]? systemEvents = null,
UpstreamAuthSettings? authSettings = null)
{
// ...
}
}
builderIResourceBuilder<AzureWebPubSubHubResource>The builder for a Web PubSub hub.
urlExpressionReferenceExpressionThe expression to evaluate the URL template configured for the event handler.
userEventPatternstringoptionalThe user event pattern for the event handler.
systemEventsstring[]?optionalThe system events for the event handler.
authSettingsUpstreamAuthSettings?optionalThe auth settings configured for the event handler.
This overload is not available in polyglot app hosts. Configure Web PubSub event handlers without auth settings in polyglot app hosts.
AddHub(IResourceBuilder<AzureWebPubSubResource>, string)Section titled AddHub(IResourceBuilder<AzureWebPubSubResource>, string)extensionIResourceBuilder<AzureWebPubSubHubResource>
Add hub settings
public static class AzureWebPubSubExtensions
{
public static IResourceBuilder<AzureWebPubSubHubResource> AddHub(
this IResourceBuilder<AzureWebPubSubResource> builder,
string hubName)
{
// ...
}
}
builderIResourceBuilder<AzureWebPubSubResource>The builder for the distributed application.
hubNamestringThe hub name. Hub name is case-insensitive.
This overload is not available in polyglot app hosts. Use the named hub overload instead.
AddHub(IResourceBuilder<AzureWebPubSubResource>, string, string?)Section titled AddHub(IResourceBuilder<AzureWebPubSubResource>, string, string?)extensionIResourceBuilder<AzureWebPubSubHubResource>
Adds an Azure Web Pub Sub hub resource to the application model.
public static class AzureWebPubSubExtensions
{
public static IResourceBuilder<AzureWebPubSubHubResource> AddHub(
this IResourceBuilder<AzureWebPubSubResource> builder,
string name,
string? hubName = null)
{
// ...
}
}
builderIResourceBuilder<AzureWebPubSubResource>The Azure WebPubSub resource builder.
namestringThe name of the Azure WebPubSub Hub resource.
hubNamestring?optionalThe name of the Azure WebPubSub Hub. If not provided, this defaults to the same value as name.
IResourceBuilder<AzureWebPubSubHubResource>A reference to the ApplicationModel.IResourceBuilder`1.
WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<AzureWebPubSubResource>, WebPubSubBuiltInRole[])Section titled WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<AzureWebPubSubResource>, WebPubSubBuiltInRole[])extensionIResourceBuilder<T>
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 class AzureWebPubSubExtensions
{
public static IResourceBuilder<T> WithRoleAssignments<T>(
this IResourceBuilder<T> builder,
IResourceBuilder<AzureWebPubSubResource> target,
params WebPubSubBuiltInRole[] roles)
{
// ...
}
}
builderIResourceBuilder<T>The resource to which the specified roles will be assigned.
targetIResourceBuilder<AzureWebPubSubResource>The target Azure Web PubSub resource.
rolesWebPubSubBuiltInRole[]The built-in Web PubSub roles to be assigned.
IResourceBuilder<T>The updated ApplicationModel.IResourceBuilder`1 with the applied role assignments.
This overload is not available in polyglot app hosts. Use AzureWebPubSubExtensions.WithRoleAssignments instead. 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);