internal static EventHandlerDelegate FromEventHandler <TEvent>(IEventAsyncHandler <TEvent> eventAsyncHandler) where TEvent : class, IEvent { return(new EventHandlerDelegate(async(inputEvent, ct) => { TEvent @event = EnsureValidEvent <TEvent>(inputEvent); await eventAsyncHandler.HandleAsync(@event, ct).ConfigureAwait(false); })); }
internal static MessageHandlerDelegate FromEventHandler <TEvent>(IEventAsyncHandler <TEvent> eventAsyncHandler) where TEvent : class { if (eventAsyncHandler == null) { throw new ArgumentNullException(nameof(eventAsyncHandler)); } return((inputEvent, ct) => eventAsyncHandler.HandleAsync((TEvent)inputEvent, ct)); }
internal static EventHandlerDelegate FromFactory <TEvent>(Func <IEventAsyncHandler <TEvent> > eventHandlerFactory) where TEvent : class, IEvent { return(new EventHandlerDelegate(async(inputEvent, ct) => { TEvent @event = EnsureValidEvent <TEvent>(inputEvent); IEventAsyncHandler <TEvent> instance = EnsureInstanceFromFactory(eventHandlerFactory); await instance.HandleAsync(@event, ct).ConfigureAwait(false); })); }