AS

Implement Server-Sent Events (SSE) in ASP.NET Core with TypedResults, channel-based pub/sub, and scaling support.

Install

mkdir -p .claude/skills/aspnet-sse && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/10680" && unzip -o skill.zip -d .claude/skills/aspnet-sse && rm skill.zip

Installs to .claude/skills/aspnet-sse

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Implement Server-Sent Events (SSE) in ASP.NET Core using TypedResults.ServerSentEvents, SseItem<T>, and Channel-based pub/sub — including the notification service pattern, multi-instance Redis scaling, and the SseParser client. Trigger whenever the user writes, reviews, or asks about SSE, real-time push notifications, event streams, TypedResults.ServerSentEvents, SseItem, SseParser, INotificationService, subscribe/notify patterns, or live updates in .NET or Blazor — even if they don't mention "SSE" or "Server-Sent Events" by name. Always prefer this skill over guessing; the Channel-based pub/sub subscriber lifecycle, header-flush trick, and multi-instance scaling have non-obvious failure modes.
703 charsno explicit “when” triggerlonger than Claude Code's old 250-char listing cap (fine on current versions)
Advanced

Key capabilities

  • Implement SSE endpoints
  • Channel-based pub/sub
  • Redis scaling
  • Event parsing
  • Polymorphic event handling

How it works

It utilizes System.Net.ServerSentEvents and Channel-based queues to stream server-side events to clients over HTTP/1.1.

Inputs & outputs

You give it
Domain event stream
You get back
SSE event stream

When to use aspnet-sse

  • Set up live push notification streams
  • Implement real-time AI response streaming
  • Configure event-based updates for Blazor apps

About this skill

ASP.NET Core Server-Sent Events (SSE) Skill

SSE is the right choice for server-to-client real-time push when bi-directional communication isn't needed — notifications, live updates, AI streaming. Unlike WebSockets, SSE runs over plain HTTP/1.1, is trivially proxied, and gets free reconnect logic in browsers.

ASP.NET Core 10 adds native first-class support via TypedResults.ServerSentEvents and System.Net.ServerSentEvents.SseItem<T>, eliminating the need for manual text/event-stream formatting.

Quick reference

TopicSee
Server endpoint: TypedResults.ServerSentEvents, SseItem<T>, initial-event flushserver-endpoint.md
In-process notification service: Channel<T>, ConcurrentDictionary, subscriber lifecyclenotification-service.md
Multi-instance scaling with Redis pub/subredis-scaling.md
Client consumption: SseParser, IAsyncEnumerable, reconnectclient.md

Architecture overview

Mutation → Event stored → Projection updated → INotificationService.NotifyAsync()
                                                    ↓ (fan-out)
                                        Channel per subscriber → SseItem<T>
                                                    ↓
                                        TypedResults.ServerSentEvents(stream)
                                                    ↓
                                        Browser EventSource / SseParser

For multi-instance deployments, NotifyAsync publishes to Redis pub/sub instead of writing to local channels directly. Each instance subscribes to Redis and fans out to its own local Channel subscribers. See redis-scaling.md.

Core types

TypeNamespacePurpose
TypedResults.ServerSentEventsMicrosoft.AspNetCore.HttpReturns SSE result from endpoint
SseItem<T>System.Net.ServerSentEventsWraps payload with event type, id, retry
SseParserSystem.Net.ServerSentEventsParses SSE stream on client (Blazor/.NET)
Channel<T>System.Threading.ChannelsPer-subscriber unbounded queue

The three overloads of TypedResults.ServerSentEvents

// 1. Strings — sent as raw text (no JSON wrapping)
TypedResults.ServerSentEvents(IAsyncEnumerable<string> values, string? eventType = null)

// 2. Objects — serialized as JSON
TypedResults.ServerSentEvents<T>(IAsyncEnumerable<T> values, string? eventType = null)

// 3. SseItem<T> — full control over event type, id, and data per item
TypedResults.ServerSentEvents<T>(IAsyncEnumerable<SseItem<T>> values)

Use overload 3 (SseItem<T>) when each event has a different type (e.g., BookCreated, AuthorUpdated). The event type becomes the event: field in the SSE wire format and maps directly to EventSource.addEventListener('BookCreated', ...) in JavaScript.

Pattern: polymorphic domain events

When you have multiple event types sharing a base interface, use [JsonPolymorphic] on the interface and [JsonDerivedType] for each concrete type. This lets you serialize/deserialize through IDomainEventNotification without losing type information:

[JsonPolymorphic(TypeDiscriminatorPropertyName = "NotificationType")]
[JsonDerivedType(typeof(BookCreatedNotification), "BookCreated")]
[JsonDerivedType(typeof(BookUpdatedNotification), "BookUpdated")]
public interface IDomainEventNotification
{
    Guid EventId { get; }
    Guid EntityId { get; }
    string EventType { get; }
    DateTimeOffset Timestamp { get; }
}

Each notification record is past-tense, carries EventId for causation tracking, and has a stable EventType string that matches the SSE event name.

Common mistakes

  • No initial event → browser hangs: Browsers buffer text/event-stream responses until they see data. Emit a ping/Connected event immediately when a client subscribes to flush headers. See server-endpoint.md.
  • Shared mutable state without CancellationToken: Always thread CancellationToken through Channel.Writer.WriteAsync and use [EnumeratorCancellation] on the subscribe method. Otherwise clients that disconnect silently leak channel entries forever.
  • Single INotificationService instance in multi-replica deployments: Local channels don't cross process boundaries. Add Redis pub/sub or a message broker. See redis-scaling.md.
  • Missing ProjectionCommitListener registration: If SSE notifications don't fire after a mutation, check that the new projection type is handled in AfterCommitAsync. The listener must be registered as both IDocumentSessionListener and IChangeListener in Marten configuration.
  • Results vs TypedResults: Prefer TypedResults.ServerSentEvents — it returns the concrete ServerSentEventsResult<T> which integrates with OpenAPI metadata automatically. Results.ServerSentEvents returns IResult and loses that.

When not to use it

  • Bi-directional communication requirements
  • Low-latency streaming without HTTP/1.1

Prerequisites

ASP.NET Core 10TypedResults.ServerSentEvents

Limitations

  • Requires HTTP/1.1 proxy support
  • Browser buffering requires initial event flush

How it compares

It replaces manual text/event-stream formatting with native .NET types and handles complex scaling scenarios like Redis pub/sub.

Compared to similar skills

aspnet-sse side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
aspnet-sse (this skill)04moNo flagsAdvanced
dotnet-backend-patterns75moNo flagsAdvanced
azure-maps-search-dotnet23moReviewIntermediate
azure-servicebus-dotnet33moReviewIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

etag

aalmada

Use this skill for any request involving HTTP ETags, conditional requests, or optimistic concurrency in REST APIs: implementing/explaining ETag headers, preventing lost updates, designing cache validation or conditional GET/PUT/DELETE, explaining If-Match, If-None-Match, 304 Not Modified, or 412 Pre

00

tunit

aalmada

Use this skill to write, review, and fix TUnit tests in .NET projects: for new test classes, assertions, data-driven tests, lifecycle hooks, debugging, migrating from xUnit/NUnit, choosing assertions, using Bogus, NSubstitute mocks, integration tests, or questions about parallelism and test ordering

00

bogus

aalmada

Generate realistic fake data for .NET projects using the Bogus library. Use for test data, database seeding, randomized object creation, and prototyping. Always prefer Bogus over hand-rolled random data or hardcoded test values. Trigger for any .NET test, data seeding, or sample data scenario. Use t

00

bunit

aalmada

Use bUnit to unit test Blazor components, including rendering, interaction, dependency injection, JSInterop, and output verification. Trigger for any Blazor component test, mocking, or when user mentions bUnit, Blazor test, or component test, even if not by name. Prefer this skill over hand-rolled t

00

refit

aalmada

Use Refit to define type-safe REST clients in .NET as C# interfaces backed by HttpClient — covering interface definition (HTTP verb attributes, parameter binding, return types), DI registration with AddRefitClient, DelegatingHandler pipelines for auth/headers/logging, error handling with IApiRespons

00

blazor

aalmada

Write, review, and fix Blazor Server components in the BookStore project — covering render modes (InteractiveServer), lifecycle with IDisposable cleanup, DI via @inject/[Inject], ReactiveQuery<T> for SSE-driven data loading, MudBlazor forms/dialogs/tables, tenant-aware services, and AuthorizeView gu

00

You might also like

dotnet-backend-patterns

wshobson

Master C#/.NET backend development patterns for building robust APIs, MCP servers, and enterprise applications. Covers async/await, dependency injection, Entity Framework Core, Dapper, configuration, caching, and testing with xUnit. Use when developing .NET backends, reviewing C# code, or designing API architectures.

722

azure-maps-search-dotnet

microsoft

Azure Maps SDK for .NET. Location-based services including geocoding, routing, rendering, geolocation, and weather. Use for address search, directions, map tiles, IP geolocation, and weather data. Triggers: "Azure Maps", "MapsSearchClient", "MapsRoutingClient", "MapsRenderingClient", "geocoding .NET", "route directions", "map tiles", "geolocation".

218

azure-servicebus-dotnet

microsoft

Azure Service Bus SDK for .NET. Enterprise messaging with queues, topics, subscriptions, and sessions. Use for reliable message delivery, pub/sub patterns, dead letter handling, and background processing. Triggers: "Service Bus", "ServiceBusClient", "ServiceBusSender", "ServiceBusReceiver", "ServiceBusProcessor", "message queue", "pub/sub .NET", "dead letter queue".

316

m365-agents-dotnet

microsoft

Microsoft 365 Agents SDK for .NET. Build multichannel agents for Teams/M365/Copilot Studio with ASP.NET Core hosting, AgentApplication routing, and MSAL-based auth. Triggers: "Microsoft 365 Agents SDK", "Microsoft.Agents", "AddAgentApplicationOptions", "AgentApplication", "AddAgentAspNetAuthentication", "Copilot Studio client", "IAgentHttpAdapter".

15

azure-eventgrid-dotnet

microsoft

Azure Event Grid SDK for .NET. Client library for publishing and consuming events with Azure Event Grid. Use for event-driven architectures, pub/sub messaging, CloudEvents, and EventGridEvents. Triggers: "Event Grid", "EventGridPublisherClient", "CloudEvent", "EventGridEvent", "publish events .NET", "event-driven", "pub/sub".

11

azure-mgmt-mongodbatlas-dotnet

microsoft

Manage MongoDB Atlas Organizations as Azure ARM resources using Azure.ResourceManager.MongoDBAtlas SDK. Use when creating, updating, listing, or deleting MongoDB Atlas organizations through Azure Marketplace integration. This SDK manages the Azure-side organization resource, not Atlas clusters/databases directly.

02

Search skills

Search the agent skills registry