BlazorGatewayExtensions Methods
ClassMethods7 members
Extension methods for adding Blazor WebAssembly apps and gateway resources.
AddBlazorGateway(IDistributedApplicationBuilder, string) Section titled AddBlazorGateway(IDistributedApplicationBuilder, string)extensionIResourceBuilder<ProjectResource> Registers the built-in Blazor Gateway. During development the gateway runs from the official .NET tool. Publishing continues to use the file-based app shipped with this package.
public static class BlazorGatewayExtensions{ public static IResourceBuilder<ProjectResource> AddBlazorGateway( this IDistributedApplicationBuilder builder, string name) { // ... }}Parameters
builderIDistributedApplicationBuilder namestringRemarks
Development requires a .NET SDK compatible with the configured gateway tool package. When publishing attached Blazor WebAssembly apps, each client must target a single framework supported by this package. The client's selected SDK must be available locally and is installed in the build image. The AppHost and client projects must also be contained by a common ancestor directory with a
.sln or .slnx file; that directory is used as the Docker build context. AddBlazorWasmApp(IDistributedApplicationBuilder, string, string) Section titled AddBlazorWasmApp(IDistributedApplicationBuilder, string, string)extensionIResourceBuilder<BlazorWasmAppResource> Registers a Blazor WebAssembly project as a resource without launching it as a process. Prefer AddBlazorWasmProject<TProject> which uses IProjectMetadata for path discovery.
public static class BlazorGatewayExtensions{ public static IResourceBuilder<BlazorWasmAppResource> AddBlazorWasmApp( this IDistributedApplicationBuilder builder, string name, string projectPath) { // ... }}Parameters
builderIDistributedApplicationBuilder namestringprojectPath stringAddBlazorWasmProject(IDistributedApplicationBuilder, string) Section titled AddBlazorWasmProject(IDistributedApplicationBuilder, string)extensionIResourceBuilder<BlazorWasmAppResource> Registers a Blazor WebAssembly project as a resource using the Aspire-generated IProjectMetadata type to discover the project path. The resource name becomes the URL path prefix (e.g., "store" → served at /store/). Use WithReference() to declare service dependencies.
public static class BlazorGatewayExtensions{ public static IResourceBuilder<BlazorWasmAppResource> AddBlazorWasmProject<TProject>( this IDistributedApplicationBuilder builder, string name) { // ... }}Parameters
builderIDistributedApplicationBuilder namestringAddDotnetProjectBlazorGateway(IDistributedApplicationBuilder, string) Section titled AddDotnetProjectBlazorGateway(IDistributedApplicationBuilder, string)extensionIResourceBuilder<DotnetProjectResource> Registers the built-in Blazor Gateway backed by an experimental
Dotnet.DotnetProjectResource from Aspire.Hosting.Dotnet (the run/watch-capable .NET resource), rather than the ApplicationModel.ProjectResource used by BlazorGatewayExtensions.AddBlazorGateway . public static class BlazorGatewayExtensions{ public static IResourceBuilder<DotnetProjectResource> AddDotnetProjectBlazorGateway( this IDistributedApplicationBuilder builder, string name) { // ... }}Parameters
builderIDistributedApplicationBuilder The distributed application builder.namestringThe name of the gateway resource.Returns
IResourceBuilder<DotnetProjectResource> A reference to the ApplicationModel.IResourceBuilder`1 for the gateway resource.Remarks
During development, the gateway runs from the official .NET tool. Publishing uses the file-based
Gateway.cs app shipped with this package. The development and publish prerequisites are the same as for BlazorGatewayExtensions.AddBlazorGateway . WithBlazorClientApp(IResourceBuilder<ProjectResource>, IResourceBuilder<BlazorWasmAppResource>, string, string, bool) Section titled WithBlazorClientApp(IResourceBuilder<ProjectResource>, IResourceBuilder<BlazorWasmAppResource>, string, string, bool)extensionIResourceBuilder<ProjectResource> Attaches a Blazor WebAssembly app to the Gateway. The resource name is used as the URL path prefix (e.g., resource "store" → /store/). Service names are derived from WithReference() annotations on the WASM resource. Service references from the WASM app are automatically forwarded to the gateway so the gateway can resolve service endpoints for YARP proxying.
public static class BlazorGatewayExtensions{ public static IResourceBuilder<ProjectResource> WithBlazorClientApp( this IResourceBuilder<ProjectResource> gateway, IResourceBuilder<BlazorWasmAppResource> wasmApp, string apiPrefix = "_api", string otlpPrefix = "_otlp", bool proxyTelemetry = true) { // ... }}Parameters
gatewayIResourceBuilder<ProjectResource> The gateway resource builder.wasmApp IResourceBuilder<BlazorWasmAppResource> The Blazor WebAssembly app to attach to the gateway.apiPrefix stringoptionalThe URL path prefix for API proxy routes. Defaults to "_api" .otlpPrefix stringoptionalThe URL path prefix for OTLP proxy routes. Defaults to "_otlp" .proxyTelemetry booloptionaltrue to expose the OTLP proxy for the client app; otherwise, false.Remarks
For development and publish prerequisites, see
BlazorGatewayExtensions.AddBlazorGateway . WithBlazorClientApp(IResourceBuilder<DotnetProjectResource>, IResourceBuilder<BlazorWasmAppResource>, string, string, bool) Section titled WithBlazorClientApp(IResourceBuilder<DotnetProjectResource>, IResourceBuilder<BlazorWasmAppResource>, string, string, bool)extensionIResourceBuilder<DotnetProjectResource> Attaches a Blazor WebAssembly app to a
Dotnet.DotnetProjectResource -backed Gateway created via BlazorGatewayExtensions.AddDotnetProjectBlazorGateway . Behaves identically to BlazorGatewayExtensions.WithBlazorClientApp . public static class BlazorGatewayExtensions{ public static IResourceBuilder<DotnetProjectResource> WithBlazorClientApp( this IResourceBuilder<DotnetProjectResource> gateway, IResourceBuilder<BlazorWasmAppResource> wasmApp, string apiPrefix = "_api", string otlpPrefix = "_otlp", bool proxyTelemetry = true) { // ... }}Parameters
gatewayIResourceBuilder<DotnetProjectResource> The gateway resource builder.wasmApp IResourceBuilder<BlazorWasmAppResource> The Blazor WebAssembly app to attach to the gateway.apiPrefix stringoptionalThe URL path prefix for API proxy routes. Defaults to "_api" .otlpPrefix stringoptionalThe URL path prefix for OTLP proxy routes. Defaults to "_otlp" .proxyTelemetry booloptionaltrue to expose the OTLP proxy for the client app; otherwise, false.Returns
IResourceBuilder<DotnetProjectResource> A reference to the ApplicationModel.IResourceBuilder`1 for the gateway resource.Remarks
For development and publish prerequisites, see
BlazorGatewayExtensions.AddBlazorGateway . WithBlazorDebuggerBrowser(IResourceBuilder<BlazorWasmAppResource>, string) Section titled WithBlazorDebuggerBrowser(IResourceBuilder<BlazorWasmAppResource>, string)extensionIResourceBuilder<BlazorWasmAppResource> Configures the browser launched when starting a debug session for the Blazor WebAssembly app. The value is read when the debugger is registered on the gateway, so call this before
BlazorGatewayExtensions.WithBlazorClientApp or BlazorGatewayExtensions.WithBlazorClientApp attaches the app. public static class BlazorGatewayExtensions{ public static IResourceBuilder<BlazorWasmAppResource> WithBlazorDebuggerBrowser( this IResourceBuilder<BlazorWasmAppResource> wasmApp, string browser = "msedge") { // ... }}Parameters
wasmApp IResourceBuilder<BlazorWasmAppResource> The Blazor WebAssembly app resource builder.browserstringoptionalThe browser to use for debugging. Defaults to "msedge". Supported values include "msedge" and "chrome".