public override Task Handle(IDomainEvent request, CancellationToken cancellationToken, ServiceScope serviceFactory, Func <IEnumerable <Func <IDomainEvent, CancellationToken, Task> >, IDomainEvent, CancellationToken, Task> publish)
        {
            var handlers = serviceFactory
                           .GetInstances <IDomainEventHandlerAsync <TDomainEvent> >()
                           .Select(x => new Func <IDomainEvent, CancellationToken, Task>((theRequest, theToken) => x.HandleAsync((TDomainEvent)theRequest, theToken)));

            return(publish(handlers, request, cancellationToken));
        }
예제 #2
0
        public override async Task <TResponse> Handle(IRequest <TResponse> request, CancellationToken cancellationToken,
                                                      ServiceScope serviceFactory)
        {
            Task <TResponse> Handler() => serviceFactory.GetHandler <IRequestHandlerAsync <TRequest, TResponse> >().HandleAsync((TRequest)request, cancellationToken);

            return(await serviceFactory
                   .GetInstances <IPipelineBehavior <TRequest, TResponse> >()
                   .Reverse()
                   .Aggregate((RequestHandlerDelegate <TResponse>)Handler, (next, pipeline) => () => pipeline.Handle((TRequest)request, cancellationToken, next))());
        }
        public override Task Handle(IDomainEvent request, CancellationToken cancellationToken, ServiceScope serviceFactory)
        {
            var handlers = serviceFactory
                           .GetInstances <IDomainEventHandlerAsync <TDomainEvent> >()
                           .Select(x => new Func <IDomainEvent, CancellationToken, Task>((theRequest, theToken) => x.HandleAsync((TDomainEvent)theRequest, theToken)));

            var tasks = handlers.Select(h => h(request, cancellationToken)).ToArray();

            Task.WaitAll(tasks);
            return(Task.CompletedTask);
        }
        public override async Task Handle(IRequest request, CancellationToken cancellationToken, ServiceScope serviceFactory)
        {
            var handlers = serviceFactory
                           .GetInstances <IRequestHandlerAsync <TRequest> >()
                           .Select(x => new Func <IRequest, CancellationToken, Task>((theRequest, theToken) => x.HandleAsync((TRequest)theRequest, theToken)));

            foreach (var handler in handlers)
            {
                await handler(request, cancellationToken);
            }
        }