-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Adding notification publisher strategies #838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
This PR introduces the idea of notification publishers as a separate class to be injected into the public class Mediator : IMediator
{
public Mediator(IServiceProvider serviceProvider)
- => _serviceProvider = serviceProvider;
+ : this(serviceProvider, new ForeachAwaitPublisher()) { }
+ public Mediator(IServiceProvider serviceProvider, INotificationPublisher publisher)
+ {
+ _serviceProvider = serviceProvider;
+ _publisher = publisher;
+ }Two new publishing strategies added:
The publishing strategies now can accept the handler instance, for cases when ordering is needed: +public interface INotificationPublisher
+{
+ Task Publish(IEnumerable<NotificationHandlerExecutor> handlerExecutors, INotification notification,
+ CancellationToken cancellationToken);
+ }
+ public record NotificationHandlerExecutor(object HandlerInstance, Func<INotification, CancellationToken, Task> HandlerCallback);This required a breaking change in the public class Mediator : IMediator {
- protected virtual async Task PublishCore(IEnumerable<Func<INotification, CancellationToken, Task>> allHandlers, INotification notification, CancellationToken cancellationToken)
- {
- foreach (var handler in allHandlers)
- {
- await handler(notification, cancellationToken).ConfigureAwait(false);
- }
- }
+ protected virtual Task PublishCore(IEnumerable<NotificationHandlerExecutor> handlerExecutors, INotification notification, CancellationToken cancellationToken)
+ => _publisher.Publish(handlerExecutors, notification, cancellationToken);
}The notification publisher can be configured via + public INotificationPublisher NotificationPublisher { get; set; } = new ForeachAwaitPublisher();
+ public Type? NotificationPublisherType { get; set; }The |
|
awesome! |
|
Will this feature be included in the next version? Very much looking forward to |
I did not pull all the possible options from @remcoros 's samples. Just the basic couple options.