Skip to content

Commit 8a9784a

Browse files
committed
More doc updates
1 parent f32e8cc commit 8a9784a

File tree

1 file changed

+13
-35
lines changed

1 file changed

+13
-35
lines changed

docs/guide/getting-started.md

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ Endpoints are generated automatically for all handlers:
8686
public record CreateTodo(string Title);
8787
public record GetTodo(string Id);
8888

89-
[HandlerCategory("Todos", RoutePrefix = "todos")]
9089
public class TodoHandler
9190
{
9291
public Todo Handle(CreateTodo cmd) => new(Guid.NewGuid().ToString(), cmd.Title);
@@ -96,35 +95,18 @@ public class TodoHandler
9695

9796
```csharp
9897
// Program.cs
99-
app.MapMyAppEndpoints(); // generated extension method
98+
app.MapMyAppEndpoints(); // generated extension method based on project name
10099
```
101100

102101
This generates:
103102

104-
- `POST /api/todos``TodoHandler.Handle(CreateTodo)`
105-
- `GET /api/todos/{id}``TodoHandler.Handle(GetTodo)`
103+
- `POST /api/todo``TodoHandler.Handle(CreateTodo)`
104+
- `GET /api/todo/{id}``TodoHandler.Handle(GetTodo)`
106105

107106
<!-- -->
108107

109108
HTTP methods, routes, and parameter binding are all inferred from message names and properties. Pass `logEndpoints: true` to see all mapped routes at startup:
110109

111-
```csharp
112-
app.MapMyAppEndpoints(logEndpoints: true);
113-
```
114-
115-
Need to customize a specific endpoint? Use the `[HandlerEndpoint]` attribute:
116-
117-
```csharp
118-
public class TodoHandler
119-
{
120-
[HandlerEndpoint(Route = "/todos/search", HttpMethod = "GET")]
121-
public Task<Result<Todo[]>> HandleAsync(SearchTodos query) { /* ... */ }
122-
123-
[HandlerEndpoint(Streaming = EndpointStreaming.ServerSentEvents, SseEventType = "todo")]
124-
public async IAsyncEnumerable<Todo> Handle(SubscribeToTodos msg) { /* ... */ }
125-
}
126-
```
127-
128110
See [Endpoints](./endpoints) for route customization, OpenAPI metadata, authorization, and more.
129111

130112
## Result Types
@@ -152,7 +134,7 @@ When used with generated endpoints, `Result<T>` maps automatically to the correc
152134
Publish messages to multiple handlers with `PublishAsync`:
153135

154136
```csharp
155-
public record OrderCreated(string OrderId, DateTime CreatedAt);
137+
public record OrderCreated(string OrderId, DateTime CreatedAt) : INotification;
156138

157139
// Both handlers run when OrderCreated is published
158140
public class EmailHandler
@@ -176,25 +158,21 @@ Handlers can even return cascading events as tuple results — see [Cascading Me
176158

177159
### Dynamic Subscriptions
178160

179-
For real-time push scenarios like SSE, subscribe to published notifications as an async stream:
161+
Subscribe to published notifications as an async stream — and combine with a streaming handler to get a real-time SSE endpoint in just a few lines:
180162

181163
```csharp
182-
await foreach (var evt in mediator.SubscribeAsync<OrderCreated>(cancellationToken: ct))
164+
public class EventStreamHandler(IMediator mediator)
183165
{
184-
Console.WriteLine($"Order created: {evt.OrderId}");
185-
}
186-
```
187-
188-
Subscribe to **all** published notifications at once using `INotification`:
189-
190-
```csharp
191-
await foreach (var evt in mediator.SubscribeAsync<INotification>(cancellationToken: ct))
192-
{
193-
Console.WriteLine($"{evt.GetType().Name} published");
166+
[HandlerEndpoint(Route = "/events/stream", Streaming = EndpointStreaming.ServerSentEvents)]
167+
public async IAsyncEnumerable<object> Handle(SubscribeToEvents message, [EnumeratorCancellation] CancellationToken ct)
168+
{
169+
await foreach (var evt in mediator.SubscribeAsync<INotification>(cancellationToken: ct))
170+
yield return evt;
171+
}
194172
}
195173
```
196174

197-
You can also subscribe to a custom marker interface (e.g., `IDispatchToClient`) to receive a targeted subset — no bridging layer or relay pipeline needed. See [Dynamic Subscriptions](./streaming-handlers#dynamic-subscriptions-with-subscribeasync) for the full API.
175+
Every notification published anywhere in the app is now pushed to connected clients over SSE — no bridging layer needed. You can subscribe to any type, including interfaces; any published notification assignable to the type parameter will be delivered. See [Dynamic Subscriptions](./streaming-handlers#dynamic-subscriptions-with-subscribeasync) for the full API.
198176

199177
## Middleware
200178

0 commit comments

Comments
 (0)