Dispatcher Overview
The Arbiter Dispatcher libraries provide a unified IDispatcher abstraction for sending commands and queries from Blazor components. The Dispatcher is designed specifically for Blazor applications and includes full support for Blazor Auto render mode, automatically wiring the correct transport based on whether a component is rendered in WebAssembly or Server Interactive mode.
| Library | Package | Description |
|---|---|---|
| Arbiter.Dispatcher.Server | ASP.NET Core endpoint that receives and routes dispatcher messages from Blazor WASM clients | |
| Arbiter.Dispatcher.Client | Client-side dispatcher implementations for WASM (JSON/MessagePack) and Server Interactive modes |
Architecture
The Dispatcher introduces a thin abstraction—IDispatcher—over IMediator. Blazor components always depend on IDispatcher, never on the underlying transport. The correct implementation is registered at startup depending on the render mode:
Blazor Component
│
▼
IDispatcher
├── WASM mode:
│ JsonDispatcher / MessagePackDispatcher
│ ──► HTTP POST /api/dispatcher/send
│ ──► DispatcherEndpoint
│ ──► IMediator ──► Handler
│
└── Server Interactive mode:
ServerDispatcher
──► IMediator ──► Handler (in-process, no HTTP hop)
Command and query flow — WASM mode
- A Blazor WASM component calls
IDispatcher.Send(request). JsonDispatcherorMessagePackDispatcherserializes the request and posts it toPOST /api/dispatcher/sendon the server.- The
X-Message-Request-TypeHTTP header carries the assembly-qualified type name so the server can deserialize the payload correctly. DispatcherEndpointresolves the CLR type, deserializes the body, injects the currentClaimsPrincipal, and forwards the request toIMediator.- The mediator runs the handler pipeline and returns the response.
- The response is serialized (JSON or MessagePack) and streamed back to the client.
Command and query flow — Server Interactive mode
- A Blazor Server component calls
IDispatcher.Send(request). ServerDispatcherdelegates directly toIMediatorin-process—no HTTP hop occurs.- The mediator runs the handler pipeline and returns the response.
Blazor Auto render mode
In Blazor Auto render mode, a component may pre-render on the server and later activate in WebAssembly. Register both ServerDispatcher and the chosen remote dispatcher in the same application:
- In the Blazor host project (e.g.
Tracker.Web): registerAddServerDispatcher()for Server Interactive rendering andAddDispatcherService()to serve WASM clients. - In the WASM client project (e.g.
Tracker.Client): registerAddMessagePackDispatcher(...)for WebAssembly rendering.
The DI container for each render environment resolves IDispatcher to the appropriate implementation automatically.
Installation
Server package
Install Arbiter.Dispatcher.Server in the Blazor host (server) project:
Install-Package Arbiter.Dispatcher.Server
OR
dotnet add package Arbiter.Dispatcher.Server
Client package
Install Arbiter.Dispatcher.Client in both the WASM client project and the Blazor host project:
Install-Package Arbiter.Dispatcher.Client
OR
dotnet add package Arbiter.Dispatcher.Client
Minimal configuration
WASM client project (Tracker.Client/Program.cs)
var builder = WebAssemblyHostBuilder.CreateDefault(args);
// Register the MessagePack dispatcher for WebAssembly rendering
builder.Services
.AddMessagePackDispatcher((sp, client) =>
{
client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress);
});
await builder.Build().RunAsync();
Blazor host project (Tracker.Web/Program.cs)
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.Services
.AddRazorComponents()
.AddInteractiveServerComponents()
.AddInteractiveWebAssemblyComponents();
// Register the server dispatcher for Server Interactive rendering
builder.Services.AddServerDispatcher();
// Register the DispatcherEndpoint to serve WASM clients
builder.Services.AddDispatcherService();
var app = builder.Build();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode()
.AddInteractiveWebAssemblyRenderMode()
.AddAdditionalAssemblies(typeof(Client.Routes).Assembly);
// Map the /api/dispatcher/send endpoint; apply authorization as needed
app.MapDispatcherService().RequireAuthorization();
app.Run();
Note:
AddDispatcherService()registers theDispatcherEndpointsingleton and MessagePack serializer options.MapDispatcherService()maps thePOST /api/dispatcher/sendroute. Both are required when WASM clients are in use.
Next steps
- Server configuration — routing, serialization, security, and diagnostics for the server-side dispatcher endpoint.
- Client configuration — DI registration, sending commands and queries, and choosing between JSON and MessagePack.
- State management — using
ModelStateManager,ModelStateLoader,ModelStateEditor, andDispatcherDataServicein Blazor components.