Skip to content

Instantly share code, notes, and snippets.

@romipetrelis
Created November 15, 2017 20:56
Show Gist options
  • Save romipetrelis/2090ffdc24f6bb7592222b87f2d02009 to your computer and use it in GitHub Desktop.
Save romipetrelis/2090ffdc24f6bb7592222b87f2d02009 to your computer and use it in GitHub Desktop.
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