Summary
Currently, DispatchR supports open generic pipeline behaviors for requests (e.g., IPipelineBehavior<TRequest, TResponse>), allowing for global/intercepting logic across all request or stream types. However, there is no equivalent for generic notification handlers – all notification handlers must be registered for specific notification types.
Problem
- There is currently no way to register a global
INotificationHandler<TNotification> (open generic notification handler) that would handle all notifications, regardless of the actual notification type.
- Developers might want to implement cross-cutting logic (such as logging, auditing, or metrics) for all notifications in a single place, just as with generic pipeline behaviors.
Proposal
- Support registration and correct resolution of open generic notification handlers, such as:
public class GlobalNotificationLogger<TNotification> : INotificationHandler<TNotification> where TNotification : INotification
{
public ValueTask Handle(TNotification notification, CancellationToken token) { /* ... */ }
}
- When a notification is published, any applicable open generic notification handlers should be resolved and invoked along with type-specific handlers.
- This would bring the notification pipeline on par with the existing pipeline behavior mechanism for requests.
Possible Solution
- Extend
ServiceRegistrator.RegisterNotification to detect and register open generic notification handlers.
- At publish time, resolve both specific and open generic handlers for the notification type.
- Follow a similar resolution logic as current pipeline behavior to avoid duplicates and support ordering if needed.
Motivation / Use cases
- Centralized notification logging/auditing
- Adding metrics, distributed tracing, or global fallback logic
- Writing less repetitive code when applying the same operation to all notifications
References
- This feature is common in some mediator/messaging frameworks (both MediatR and pipeline support are already in DispatchR for requests)
Thank you for considering this enhancement!
Summary
Currently, DispatchR supports open generic pipeline behaviors for requests (e.g.,
IPipelineBehavior<TRequest, TResponse>), allowing for global/intercepting logic across all request or stream types. However, there is no equivalent for generic notification handlers – all notification handlers must be registered for specific notification types.Problem
INotificationHandler<TNotification>(open generic notification handler) that would handle all notifications, regardless of the actual notification type.Proposal
Possible Solution
ServiceRegistrator.RegisterNotificationto detect and register open generic notification handlers.Motivation / Use cases
References
Thank you for considering this enhancement!