BlazorAutoBridge 2.1.0

dotnet add package BlazorAutoBridge --version 2.1.0
                    
NuGet\Install-Package BlazorAutoBridge -Version 2.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BlazorAutoBridge" Version="2.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BlazorAutoBridge" Version="2.1.0" />
                    
Directory.Packages.props
<PackageReference Include="BlazorAutoBridge" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BlazorAutoBridge --version 2.1.0
                    
#r "nuget: BlazorAutoBridge, 2.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package BlazorAutoBridge@2.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BlazorAutoBridge&version=2.1.0
                    
Install as a Cake Addin
#tool nuget:?package=BlazorAutoBridge&version=2.1.0
                    
Install as a Cake Tool

Introduction

BlazorAutoBridge is a source generator that produces all the necessary code for making external API calls in a Blazor Auto Render Mode application. It eliminates repetitive and error-prone boilerplate, allowing developers to focus on business logic rather than plumbing code.

Architecture Overview

In Blazor Auto Render Mode, all external API calls made from the WebAssembly client are routed through an internal API hosted on the server. The internal API then forwards the request to the actual external API. This approach is illustrated in the diagram below:

Blazor Auto Render Mode BFF Architecture

Getting Started

Install NuGet Package

Add the NuGet package to both the Client and Server projects:

Install-Package BlazorAutoBridge -Version 2.0.0

Add these Nuget packages to the Client project:

Install-Package RestEase -Version 1.6.4
Install-Package RestEase.HttpClientFactory -Version 1.6.4

Define RestEase API Interfaces

Create your API interfaces that describe the endpoints you want to call using RestEase. These interfaces will be used by the source generator to create the implementation code. These interfaces must be defined in both the Client and Server projects, as they are used to generate the necessary code for API calls.

For example, create a file named IUserService.cs in both Client and Server projects:

[ApiService] // marker Attribute
public interface IUserApi
{
	[Get("users")]
	Task<IEnumerable<UserDto>> GetAllUsersAsync();
}

Client Project Setup

In the Client project's Program.cs:

using BlazorAutoBridge.DependencyInjection;

builder.Services.AddBlazorAutoBridge((sp, client) =>
{
	client.BaseAddress = new Uri($"{builder.HostEnvironment.BaseAddress}forwarders"); // don't change this
	client.Timeout = TimeSpan.FromSeconds(5);
});

Server Project Setup

In the Server project's Program.cs:

using BlazorAutoBridge.DependencyInjection;

builder.Services.AddBlazorAutoBridge((sp, client) =>
{
	client.BaseAddress = new Uri("https://localhost:7005/api/");
	client.Timeout = TimeSpan.FromSeconds(5);
});

var app = builder.Build();

// ...

app.MapControllers(); // Don't forget to add this line

app.Run();

Using Generated Services in Blazor Components

You can now inject your generated services in your Blazor components:

@inject IUserService UserService

<button @onclick="LoadUsers">Load Users</button>

@code {
	private async Task LoadUsers()
	{
		var users = await UserService.GetAllUsersAsync();
		// Handle result
	}
}
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.0 120 8/24/2025
2.0.2 128 8/9/2025
2.0.1 120 8/9/2025
2.0.0 122 8/9/2025