Skip to content

Feature: Support Open Generic Notification Handlers (Global Notification Pipeline) #47

@Billskate

Description

@Billskate

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions