signalr
π―Skillfrom stuartf303/sorcha
Enables real-time WebSocket communication for broadcasting notifications and events across groups using SignalR hubs with JWT authentication.
Installation
npx skills add https://github.com/stuartf303/sorcha --skill signalrSkill Details
|
Overview
# SignalR Skill
ASP.NET Core SignalR implementation for real-time client-server communication. Sorcha uses two hubs: ActionsHub (Blueprint Service) for workflow notifications and RegisterHub (Register Service) for ledger events. Both use group-based broadcasting with JWT authentication via query parameters.
Quick Start
Hub Implementation
```csharp
// Strongly-typed hub with client interface
public class RegisterHub : Hub
{
public async Task SubscribeToRegister(string registerId)
{
await Groups.AddToGroupAsync(Context.ConnectionId, $"register:{registerId}");
}
}
public interface IRegisterHubClient
{
Task RegisterCreated(string registerId, string name);
Task TransactionConfirmed(string registerId, string transactionId);
}
```
Sending from Services
```csharp
public class NotificationService
{
private readonly IHubContext
public async Task NotifyActionConfirmedAsync(ActionNotification notification, CancellationToken ct)
{
await _hubContext.Clients
.Group($"wallet:{notification.WalletAddress}")
.SendAsync("ActionConfirmed", notification, ct);
}
}
```
Client Connection (Testing)
```csharp
var connection = new HubConnectionBuilder()
.WithUrl($"{baseUrl}/actionshub?access_token={jwt}")
.Build();
connection.On
await connection.StartAsync();
await connection.InvokeAsync("SubscribeToWallet", walletAddress);
```
Key Concepts
| Concept | Usage | Example |
|---------|-------|---------|
| Groups | Route messages to subscribers | wallet:{address}, register:{id}, tenant:{id} |
| Typed Hubs | Compile-time safety | Hub |
| IHubContext | Send from services | Inject IHubContext |
| JWT Auth | Query parameter auth | ?access_token={jwt} |
Common Patterns
Service Abstraction Over Hub
When: Decoupling business logic from SignalR implementation
```csharp
// Interface in Services/Interfaces/
public interface INotificationService
{
Task NotifyActionAvailableAsync(ActionNotification notification, CancellationToken ct = default);
}
// Register in DI
builder.Services.AddScoped
```
Hub Registration in Program.cs
```csharp
builder.Services.AddSignalR();
// Map after authentication middleware
app.MapHub
app.MapHub
```
See Also
- [patterns](references/patterns.md) - Hub patterns, group routing, typed clients
- [workflows](references/workflows.md) - Testing, scaling, authentication setup
Related Skills
- aspire - Service orchestration and configuration
- jwt - Authentication token setup for hub connections
- redis - Backplane configuration for scaling
- xunit - Integration testing patterns
- fluent-assertions - Test assertions for hub tests
Documentation Resources
> Fetch latest SignalR documentation with Context7.
How to use Context7:
- Use
mcp__context7__resolve-library-idto search for "signalr aspnetcore" - Prefer website documentation (IDs starting with
/websites/) over source code - Query with
mcp__context7__query-docsusing the resolved library ID
Library ID: /websites/learn_microsoft_en-us_aspnet_core _(ASP.NET Core docs including SignalR)_
Recommended Queries:
- "SignalR hub groups authentication"
- "SignalR Redis backplane scaling"
- "SignalR strongly typed hubs"
More from this repository7
Configures .NET 10 projects with C# 13 features, service defaults, dependency injection, and modern development patterns.
Builds and manages Blazor WebAssembly components with MudBlazor, supporting multiple render modes and authentication for interactive web applications.
Orchestrates .NET Aspire microservices by configuring service discovery, telemetry, health checks, and shared configurations.
Defines and configures REST endpoints using .NET Minimal APIs with Scalar OpenAPI documentation and authorization policies.
Configures YARP reverse proxy to route API gateway requests, transform paths, and proxy microservice endpoints with flexible routing rules.
Manages Entity Framework Core database operations with PostgreSQL, enabling efficient data access, migrations, and repository patterns.
nbitcoin skill from stuartf303/sorcha