Created
November 15, 2017 20:56
-
-
Save romipetrelis/2090ffdc24f6bb7592222b87f2d02009 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IEventBroker | |
{ | |
Task Publish(object e); | |
} | |
internal class EventBroker : IEventBroker | |
{ | |
private readonly IList<DomainEventHandler> _handlers; | |
public EventBroker(IList<DomainEventHandler> subscribers) | |
{ | |
_handlers = subscribers; | |
} | |
public async Task Publish(object e) | |
{ | |
foreach (var handler in _handlers) | |
{ | |
await handler.Handle(e); | |
} | |
} | |
} | |
public abstract class DomainEventHandler | |
{ | |
public async Task Handle(object it) | |
{ | |
if (await WantToHandle(it)) | |
{ | |
await ThenHandle(it); | |
} | |
} | |
protected abstract Task<bool> WantToHandle(object it); | |
protected abstract Task ThenHandle(object it); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment