diff --git a/README.md b/README.md index 0de6ea4..313ebf1 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ 3. Notifications: 1. `INotification` 2. `INotificationHandler` + 3. Open-generic `INotificationHandler where TNotification : INotification` > :bulb: **Tip:** *If you're looking for a mediator with the raw performance of hand-written code, DispatchR is built for you.* ## ✨ How to install? @@ -62,6 +63,9 @@ public sealed class PingMediatR : IRequest { } public sealed class PingDispatchR : IRequest> { } ``` +> [!IMPORTANT] +> Always use a **generic** return type such as `Task` or `ValueTask`. Using a bare `Task` or `ValueTask` (without a type argument) may prevent the handler from being triggered when pipeline behaviors or validators are present. + ## Handler Definition ### MediatR @@ -152,7 +156,7 @@ public sealed class CounterStreamRequestMediatR : IStreamRequest { } 1. Sending `TRequest` to `IStreamRequest` ```csharp -public sealed class CounterStreamRequestDispatchR : IStreamRequest> { } +public sealed class CounterStreamRequestDispatchR : IStreamRequest { } ``` ## Stream Handler Definition @@ -171,9 +175,9 @@ public sealed class CounterStreamHandlerMediatR : IStreamRequestHandler +public sealed class CounterStreamHandlerDispatchR : IStreamRequestHandler { - public async IAsyncEnumerable Handle(CounterStreamHandlerDispatchR request, CancellationToken cancellationToken) + public async IAsyncEnumerable Handle(CounterStreamRequestDispatchR request, CancellationToken cancellationToken) { yield return 1; } @@ -248,7 +252,7 @@ public sealed class EventHandler(ILogger logger) : INotificationHandler logger) : INotificationHandler(ILogger> logger) + : INotificationHandler + where TNotification : INotification +{ + public ValueTask Handle(TNotification notification, CancellationToken cancellationToken) + { + logger.LogInformation("[Generic] Received notification of type {NotificationType}: {@Notification}", + typeof(TNotification).Name, notification); + return ValueTask.CompletedTask; + } +} +``` + # ⚡ How DispatchR Achieves High Performance ###### DispatchR is designed with one goal in mind: **maximize performance with minimal memory usage**. Here's how it accomplishes that: