public EventHandlerWrapper(IHaveConsequencesWhen <TEvent> consequenter)
 {
     if (consequenter == null)
     {
         throw new ArgumentNullException(nameof(consequenter));
     }
     InnerHandler   = consequenter;
     IsConsequenter = true;
     handle         = (@event, handler) => consequenter.HaveConsequences(@event);
 }
Example #2
0
 internal static IDisposable SubscribeConsequences <TEvent>(
     IHaveConsequencesWhen <TEvent> handler,
     IObservable <TEvent> observable,
     IEventBus bus)
     where TEvent : IEvent => observable
 .Subscribe(
     onNext : e =>
 {
     try
     {
         handler.HaveConsequences(e);
     }
     catch (Exception exception)
     {
         var error = new EventHandlingError(exception, handler, e);
         bus.PublishErrorAsync(error).Wait();
     }
 },
     onError: exception => bus.PublishErrorAsync(new EventHandlingError(exception, handler))
     .Wait());