-
Something like this: public interface IDomainNotificationHandler : INotificationHandler<DomainNotification>
{
public bool HasNotifications();
public DomainNotification? GetFirstPublishedNotification();
}
public class DomainNotificationHandler : IDomainNotificationHandler
{
private readonly List<DomainNotification> _notifications;
public IReadOnlyCollection<DomainNotification> Notifications => _notifications;
public DomainNotificationHandler()
{
_notifications = new();
}
public async Task Handle(DomainNotification notification, CancellationToken cancellationToken)
{
_notifications.Add(notification);
await Task.CompletedTask;
}
public bool HasNotifications() =>
_notifications.Any();
public DomainNotification? GetFirstPublishedNotification() =>
_notifications.FirstOrDefault();
} Is it possible? |
Beta Was this translation helpful? Give feedback.
Answered by
jbogard
Jan 27, 2023
Replies: 1 comment 1 reply
-
No, it is not. Either use |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
arakakivl
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No, it is not. Either use
INotificationHandler
or create your own interface and publisher. MediatR is not designed to be abstracted away, MediatR is the abstraction.