Skip to content
DocsTry Aspire
DocsTry

BlazorGatewayExtensions Methods

ClassMethods6 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 as a file-based C# app. The gateway is shipped as Gateway.cs alongside this library and launched via AddCSharpApp. No separate project is needed.
public static class BlazorGatewayExtensions
{
public static IResourceBuilder<ProjectResource> AddBlazorGateway(
this IDistributedApplicationBuilder builder,
string name)
{
// ...
}
}
builderIDistributedApplicationBuilder
namestring
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)
{
// ...
}
}
builderIDistributedApplicationBuilder
namestring
projectPathstring
AddBlazorWasmProject(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)
{
// ...
}
}
builderIDistributedApplicationBuilder
namestring
AddDotnetProjectBlazorGateway(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. The gateway is shipped as Gateway.cs alongside this library and launched via AddDotnetProject. No separate project is needed.
public static class BlazorGatewayExtensions
{
public static IResourceBuilder<DotnetProjectResource> AddDotnetProjectBlazorGateway(
this IDistributedApplicationBuilder builder,
string name)
{
// ...
}
}
builderIDistributedApplicationBuilder
namestring
Publishing is not yet supported for the Dotnet.DotnetProjectResource -backed gateway because the resource does not implement the container-files destination pipeline that the publish path relies on to merge each WASM client's static assets into the gateway image. Use BlazorGatewayExtensions.AddBlazorGateway for publish scenarios. This restriction is expected to be lifted once container execution lands for Dotnet.DotnetProjectResource.
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)
{
// ...
}
}
gatewayIResourceBuilder<ProjectResource>The gateway resource builder.
wasmAppIResourceBuilder<BlazorWasmAppResource>The Blazor WebAssembly app to attach to the gateway.
apiPrefixstringoptionalThe URL path prefix for API proxy routes. Defaults to "_api".
otlpPrefixstringoptionalThe URL path prefix for OTLP proxy routes. Defaults to "_otlp".
proxyTelemetrybooloptionaltrue to expose the OTLP proxy for the client app; otherwise, false.
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)
{
// ...
}
}
gatewayIResourceBuilder<DotnetProjectResource>The gateway resource builder.
wasmAppIResourceBuilder<BlazorWasmAppResource>The Blazor WebAssembly app to attach to the gateway.
apiPrefixstringoptionalThe URL path prefix for API proxy routes. Defaults to "_api".
otlpPrefixstringoptionalThe URL path prefix for OTLP proxy routes. Defaults to "_otlp".
proxyTelemetrybooloptionaltrue to expose the OTLP proxy for the client app; otherwise, false.