public override Task Handle(IMessage message, CancellationToken cancellationToken, HandlerFactory handlerFactory, Func <IEnumerable <Func <IMessage, CancellationToken, Task> >, IMessage, CancellationToken, Task> publish)
        {
            var handlers = handlerFactory
                           .GetInstances <IMessageHandler <TMessage> >()
                           .Select(x => new Func <IMessage, CancellationToken, Task>((theNotification, theToken) => x.Handle((TMessage)theNotification, theToken)));

            return(publish(handlers, message, cancellationToken));
        }
Ejemplo n.º 2
0
        public override IObservable <Unit> Handle(IRequest notification, HandlerFactory handlerFactory, Func <IEnumerable <Func <IRequest, IObservable <Unit> > >, IRequest, Unit> publish)
        {
            var handlers = handlerFactory
                           .GetInstances <IRequestHandler <TNotification, Unit> >()
                           .Select(x => new Func <IRequest, IObservable <Unit> >((theNotification) =>
            {
                // have to call subscribe to ensure execution.
                // The return Unit does not emit from the original sequence, is this okay?
                x.Handle((TNotification)theNotification).Subscribe();
                return(Observable.Return(Unit.Default));
            }));

            return(Observable.Return(publish(handlers, notification)));
        }