Exemplo n.º 1
0
 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));
        }
Exemplo n.º 3
0
        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);
            }));
        }