BlazorSignalProxyServices.Client
1.0.0
dotnet add package BlazorSignalProxyServices.Client --version 1.0.0
NuGet\Install-Package BlazorSignalProxyServices.Client -Version 1.0.0
<PackageReference Include="BlazorSignalProxyServices.Client" Version="1.0.0" />
<PackageVersion Include="BlazorSignalProxyServices.Client" Version="1.0.0" />
<PackageReference Include="BlazorSignalProxyServices.Client" />
paket add BlazorSignalProxyServices.Client --version 1.0.0
#r "nuget: BlazorSignalProxyServices.Client, 1.0.0"
#:package BlazorSignalProxyServices.Client@1.0.0
#addin nuget:?package=BlazorSignalProxyServices.Client&version=1.0.0
#tool nuget:?package=BlazorSignalProxyServices.Client&version=1.0.0
BlazorSignalProxyServices
A set of libraries that enable seamless proxy method calls between Blazor Server and Blazor WebAssembly applications using SignalR connections. This library provides a transparent way to invoke methods on services from the client side as if they were local calls, while the actual execution happens on the server.
Packages
Package | NuGet Version | Description |
---|---|---|
BlazorSignalProxyServices.Core | Core models, settings, and shared functionality | |
BlazorSignalProxyServices.Client | Client-side proxy services for Blazor WebAssembly | |
BlazorSignalProxyServices.Server | Server-side SignalR hub and services |
Features
- Transparent Method Proxying: Call server methods from client as if they were local
- Real-time Communication: Built on top of SignalR for bi-directional communication
- Async Support: Full support for asynchronous method calls with configurable timeouts
- Type-Safe: Strongly typed interfaces ensure compile-time safety
- Configurable: Settings for both client and server components
- Modular: Separate packages for Core, Client, and Server functionality
Quick Start
Server Setup (Blazor Server / ASP.NET Core)
- Install the server package:
dotnet add package BlazorSignalProxyServices.Server
- Configure services in
Program.cs
:
using BlazorSignalProxyServices.Server;
var builder = WebApplication.CreateBuilder(args);
// Add SignalR Proxy services
builder.Services.AddSignalProxyServer();
var app = builder.Build();
// Configure SignalR Proxy
app.UseSignalProxyServer();
app.Run();
Client Setup (Blazor WebAssembly)
- Install the client package:
dotnet add package BlazorSignalProxyServices.Client
- Configure services in
Program.cs
:
using BlazorSignalProxyServices.Client;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
// Add SignalR Proxy client services
var proxyClient = builder.Services.AddSignalProxyClient();
// Register your service interfaces for proxying
proxyClient.AddProxyService<IMyService>();
await builder.Build().RunAsync();
- Use proxied services in components:
@inject IMyService MyService
@code {
private async Task CallServerMethod()
{
// This call will be proxied to the server via SignalR
var result = await MyService.GetDataAsync();
}
}
Architecture
┌─────────────────────┐ SignalR ┌─────────────────────┐
│ Blazor WebAssembly │◄──────────────►│ Blazor Server │
│ │ │ │
│ ┌─────────────────┐ │ │ ┌─────────────────┐ │
│ │ Proxy Client │ │ Method Call │ │ SignalR Hub │ │
│ │ (Dynamic Proxy) │ ├────────────────┤ │ (Dispatcher) │ │
│ └─────────────────┘ │ │ └─────────────────┘ │
│ │ │ │ │
└─────────────────────┘ │ ▼ │
│ ┌─────────────────┐ │
│ │ Actual Service │ │
│ │ Implementation │ │
│ └─────────────────┘ │
└─────────────────────┘
How It Works
- Service Registration: Register your service interfaces with the proxy client
- Dynamic Proxy Creation: The library creates dynamic proxies for your service interfaces using Castle.DynamicProxy
- Method Interception: When you call a method on the proxy, it's intercepted and converted into a
ProxyFunctionInvokeRequest
- SignalR Communication: The request is sent to the server via SignalR connection
- Server Execution: The server hub receives the request and invokes the actual service method
- Response Handling: The result is sent back to the client and returned from the proxy method
Configuration
Client Settings
var clientSettings = new SignalProxyClientSettings
{
DefaultAsyncTimeout = TimeSpan.FromSeconds(30),
HubUrl = "/signalproxyhub"
};
builder.Services.AddSignalProxyClient(clientSettings);
Server Settings
var serverSettings = new SignalProxyServerSettings
{
UseResponseCompression = true,
HubPath = "/signalproxyhub"
};
builder.Services.AddSignalProxyServer(serverSettings);
Advanced Usage
Custom Interceptors
You can create custom interceptors by implementing the appropriate interfaces:
public class CustomInterceptor : IAsyncInterceptor
{
public void InterceptSynchronous(IInvocation invocation)
{
// Custom synchronous interception logic
}
public void InterceptAsynchronous(IInvocation invocation)
{
// Custom asynchronous interception logic
}
public void InterceptAsynchronous<TResult>(IInvocation invocation)
{
// Custom generic asynchronous interception logic
}
}
Error Handling
The library includes built-in error handling and timeout management. Failed method calls will throw exceptions on the client side, maintaining the expected behavior of local method calls.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Requirements
- .NET 8.0 or later
- ASP.NET Core (for server-side)
- Blazor WebAssembly (for client-side)
Dependencies
Core
- Castle.Core.AsyncInterceptor
- Microsoft.Extensions.DependencyInjection.Abstractions
Client
- Microsoft.AspNetCore.Components.WebAssembly
- Microsoft.AspNetCore.SignalR.Client
- BlazorSignalProxyServices.Core
Server
- Microsoft.AspNetCore.Components.WebAssembly.Server
- BlazorSignalProxyServices.Core
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
Version 1.0.0
- Initial release
- Core proxy functionality
- Client and server packages
- SignalR-based communication
- Async method support
- Configurable timeouts
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- BlazorSignalProxyServices.Core (>= 1.0.0)
- Castle.Core.AsyncInterceptor (>= 2.1.0)
- Microsoft.AspNetCore.Components.WebAssembly (>= 8.0.8)
- Microsoft.AspNetCore.SignalR.Client (>= 8.0.8)
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 |
---|---|---|
1.0.0 | 165 | 8/6/2025 |