From 28c510cac0a6a6521f634fe0addff62e0c83bb27 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 8 May 2026 18:52:31 +0000 Subject: [PATCH] docs: fix README issues for #44 and add generic notification handler docs (v2.1.2) Agent-Logs-Url: https://github.com/hasanxdev/DispatchR/sessions/bf9f2dea-964c-4768-b4e7-31ae7fb7ea59 Co-authored-by: hasanxdev <30981174+hasanxdev@users.noreply.github.com> --- README.md | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) 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: