Lewee.Infrastructure.ServerEvents
0.40.3
dotnet add package Lewee.Infrastructure.ServerEvents --version 0.40.3
NuGet\Install-Package Lewee.Infrastructure.ServerEvents -Version 0.40.3
<PackageReference Include="Lewee.Infrastructure.ServerEvents" Version="0.40.3" />
<PackageVersion Include="Lewee.Infrastructure.ServerEvents" Version="0.40.3" />
<PackageReference Include="Lewee.Infrastructure.ServerEvents" />
paket add Lewee.Infrastructure.ServerEvents --version 0.40.3
#r "nuget: Lewee.Infrastructure.ServerEvents, 0.40.3"
#:package Lewee.Infrastructure.ServerEvents@0.40.3
#addin nuget:?package=Lewee.Infrastructure.ServerEvents&version=0.40.3
#tool nuget:?package=Lewee.Infrastructure.ServerEvents&version=0.40.3
Lewee.Infrastructure.ServerEvents
Infrastructure utilities for ASP.NET Core Web API Server-Sent Events.
Purpose
This package provides the server-side infrastructure for broadcasting client events to connected Blazor clients using Server-Sent Events (SSE). It includes the client event broadcaster, channel configuration, and SSE endpoint.
For client-side event reception in Blazor applications, see Lewee.Infrastructure.Fluxor.
Dependencies
Microsoft.AspNetCore.App- ASP.NET Core frameworkLewee.Application- Application layer with ClientEvent notificationLewee.Common- Common utilities
Components
ClientEventChannelHandler
MediatR notification handler that fans out ClientEvent notifications to all active SSE connections (per user, or broadcast when UserId is null/empty).
internal sealed class ClientEventChannelHandler : INotificationHandler<ClientEvent>
{
public async Task Handle(ClientEvent notification, CancellationToken cancellationToken)
{
// Writes the event to all per-connection channels for the user (or all channels when broadcasting)
}
}
SSE Endpoint Configuration
AddClientEventBroadcaster
Configures the client event channel and handler:
builder.Services.AddClientEventBroadcaster();
This method:
- Registers
ConnectionManageras a singleton to manage per-connection channels - Registers
ClientEventChannelHandleras a notification handler forClientEventfan-out
MapSseEndpoint
Maps the SSE endpoint at /events for client connections:
app.MapSseEndpoint();
The endpoint:
- Requires authorization
- Filters events by the authenticated user's ID
- Streams events as Server-Sent Events
Usage
Server Setup
// In Web API Program.cs
builder.Services.AddClientEventBroadcaster();
var app = builder.Build();
app.MapSseEndpoint();
Publishing Events
// In command handler or any service
public class CreateOrderHandler : IRequestHandler<CreateOrderCommand, CommandResult>
{
private readonly IMediator mediator;
public async Task<CommandResult> Handle(CreateOrderCommand request, CancellationToken cancellationToken)
{
// ... create order logic ...
// Publish event to channel for broadcasting to connected clients
await mediator.Publish(new ClientEvent
{
ContractFullClassName = "OrderCreated",
UserId = order.UserId,
Data = JsonSerializer.Serialize(orderDto)
}, cancellationToken);
return CommandResult.Success();
}
}
For receiving events in Blazor, see Lewee.Infrastructure.Fluxor.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Lewee.Application (>= 0.40.3)
- Lewee.Common (>= 0.40.3)
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 |
|---|---|---|
| 0.40.3 | 49 | 11/22/2026 |