# BlazorGatewayExtensions Methods

- Package: [Aspire.Hosting.Blazor](/reference/api/csharp/aspire.hosting.blazor.md)
- Type: [BlazorGatewayExtensions](/reference/api/csharp/aspire.hosting.blazor/blazorgatewayextensions.md)
- Kind: `Methods`
- Members: `4`

Extension methods for adding Blazor WebAssembly apps and gateway resources.

## AddBlazorGateway(IDistributedApplicationBuilder, string)

- Name: `AddBlazorGateway(IDistributedApplicationBuilder, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ProjectResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Blazor/BlazorGatewayExtensions.cs#L37-L70)

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.

```csharp
public static class BlazorGatewayExtensions
{
    public static IResourceBuilder<ProjectResource> AddBlazorGateway(
        this IDistributedApplicationBuilder builder,
        string name)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
- `name` (`string`)

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddBlazorWasmApp(IDistributedApplicationBuilder, string, string)

- Name: `AddBlazorWasmApp(IDistributedApplicationBuilder, string, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<BlazorWasmAppResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Blazor/BlazorGatewayExtensions.cs#L110-L121)

Registers a Blazor WebAssembly project as a resource without launching it as a process. Prefer AddBlazorWasmProject<TProject> which uses IProjectMetadata for path discovery.

```csharp
public static class BlazorGatewayExtensions
{
    public static IResourceBuilder<BlazorWasmAppResource> AddBlazorWasmApp(
        this IDistributedApplicationBuilder builder,
        string name,
        string projectPath)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
- `name` (`string`)
- `projectPath` (`string`)

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddBlazorWasmProject(IDistributedApplicationBuilder, string)

- Name: `AddBlazorWasmProject(IDistributedApplicationBuilder, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<BlazorWasmAppResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Blazor/BlazorGatewayExtensions.cs#L85-L97)

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.

```csharp
public static class BlazorGatewayExtensions
{
    public static IResourceBuilder<BlazorWasmAppResource> AddBlazorWasmProject<TProject>(
        this IDistributedApplicationBuilder builder,
        string name)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
- `name` (`string`)

## ATS metadata

### Ignored by ATS

- Excluded from automatic Polyglot export.

## WithBlazorClientApp(IResourceBuilder<ProjectResource>, IResourceBuilder<BlazorWasmAppResource>, string, string, bool)

- Name: `WithBlazorClientApp(IResourceBuilder<ProjectResource>, IResourceBuilder<BlazorWasmAppResource>, string, string, bool)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<ProjectResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/becb48e2d61099e35ae336d527d3875e928d6594/src/Aspire.Hosting.Blazor/BlazorGatewayExtensions.cs#L144-L174)

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.

```csharp
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

- `gateway` (`IResourceBuilder<ProjectResource>`)
  The gateway resource builder.
- `wasmApp` (`IResourceBuilder<BlazorWasmAppResource>`)
  The Blazor WebAssembly app to attach to the gateway.
- `apiPrefix` (`string`) `optional`
  The URL path prefix for API proxy routes. Defaults to `"_api"`.
- `otlpPrefix` (`string`) `optional`
  The URL path prefix for OTLP proxy routes. Defaults to `"_otlp"`.
- `proxyTelemetry` (`bool`) `optional`
  `true` to expose the OTLP proxy for the client app; otherwise, `false`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
