コード例 #1
0
ファイル: RequestHandler.cs プロジェクト: shadowca/MediatR
        private static Task <TResponse> GetPipeline(TRequest request, RequestHandlerDelegate <TResponse> invokeHandler, MultiInstanceFactory factory)
        {
            var behaviors = factory(typeof(IPipelineBehavior <TRequest, TResponse>))
                            .Cast <IPipelineBehavior <TRequest, TResponse> >()
                            .Reverse();

            var aggregate = behaviors.Aggregate(invokeHandler, (next, pipeline) => () => pipeline.Handle(request, next));

            return(aggregate());
        }
コード例 #2
0
        public override Task Handle(INotification notification, CancellationToken cancellationToken, MultiInstanceFactory multiInstanceFactory, Func <IEnumerable <Task>, Task> publish)
        {
            var handlers = GetHandlers((TNotification)notification, cancellationToken, multiInstanceFactory);

            return(publish(handlers));
        }
コード例 #3
0
ファイル: Mediator.cs プロジェクト: samueldjack/MediatR
 /// <summary>
 /// Initializes a new instance of the <see cref="Mediator"/> class.
 /// </summary>
 /// <param name="singleInstanceFactory">The single instance factory.</param>
 /// <param name="multiInstanceFactory">The multi instance factory.</param>
 public Mediator(SingleInstanceFactory singleInstanceFactory, MultiInstanceFactory multiInstanceFactory) :
     this(singleInstanceFactory, multiInstanceFactory, new MediatorConfiguration() { PublishAsyncOptions = PublishAsyncOptions.Parallel })
 {
 }
コード例 #4
0
ファイル: CommandHandler.cs プロジェクト: pmdevers/Servicebus
        public override Task <TResult> HandleAsync(ICommand <TResult> command, CancellationToken cancellationToken,
                                                   SingleInstanceFactory singleFactory, MultiInstanceFactory multiFactory)
        {
            var handler = GetHandler((TCommand)command, cancellationToken, singleFactory);

            var pipeline = GetPipeline((TCommand)command, handler, multiFactory);

            return(pipeline);
        }
コード例 #5
0
 private static IEnumerable <THandler> GetHandlers <THandler>(MultiInstanceFactory factory)
 {
     return(factory(typeof(THandler)).Cast <THandler>());
 }
コード例 #6
0
 public SequentialMediator(SingleInstanceFactory singleInstanceFactory, MultiInstanceFactory multiInstanceFactory) : base(singleInstanceFactory, multiInstanceFactory)
 {
 }
コード例 #7
0
 public AppMediator(MultiInstanceFactory multiInstanceFactory, SingleInstanceFactory singleInstanceFactory, IHttpContextAccessor httpContextAccessor, IAppDataContext appDataContext)
 {
     _inner = new Mediator(singleInstanceFactory, multiInstanceFactory);
     _httpContextAccessor = httpContextAccessor;
     _appDataContext      = appDataContext;
 }
コード例 #8
0
        public override Task Handle(INotification notification, CancellationToken cancellationToken, IMediatorContext context, MultiInstanceFactory multiInstanceFactory, Func <IEnumerable <RequestHandlerDelegate <Unit> >, Task> publish)
        {
            var handlers = GetHandlers((TNotification)notification, cancellationToken, context, multiInstanceFactory);
            var pipeline = GetPipeline((TNotification)notification, context, handlers, multiInstanceFactory, publish);

            return(pipeline);
        }
コード例 #9
0
        public override Task Handle(IEvent @event, ReactiveObject state, MultiInstanceFactory factory)
        {
            var tasks = GetTasks(@event, state, factory);

            return(Task.WhenAll(tasks));
        }
コード例 #10
0
 public SequentialMediator(SingleInstanceFactory single, MultiInstanceFactory multi)
 {
     innerMediator = new Mediator(single, multi);
 }
コード例 #11
0
 public abstract Task Handle(IEvent @event, ReactiveObject state, MultiInstanceFactory factory);
コード例 #12
0
ファイル: Mediator.cs プロジェクト: preemajames/AsyncMediator
 public Mediator(MultiInstanceFactory multiInstanceFactory, SingleInstanceFactory singleInstanceFactory)
 {
     _factory = new Factory(multiInstanceFactory, singleInstanceFactory);
 }
コード例 #13
0
        private IEnumerable <Task> GetHandlers(TNotification notification, CancellationToken cancellationToken, MultiInstanceFactory factory)
        {
            var notificationHandlers = GetHandlers <INotificationHandler <TNotification> >(factory)
                                       .Select(x =>
            {
                x.Handle(notification);
                return(Unit.Task);
            });

            var asyncNotificationHandlers = GetHandlers <IAsyncNotificationHandler <TNotification> >(factory)
                                            .Select(x => x.Handle(notification));

            var cancellableAsyncNotificationHandlers = GetHandlers <ICancellableAsyncNotificationHandler <TNotification> >(factory)
                                                       .Select(x => x.Handle(notification, cancellationToken));

            var allHandlers = notificationHandlers
                              .Concat(asyncNotificationHandlers)
                              .Concat(cancellableAsyncNotificationHandlers);

            return(allHandlers);
        }
コード例 #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Mediator"/> class.
 /// </summary>
 /// <param name="singleInstanceFactory">The single instance factory.</param>
 /// <param name="multiInstanceFactory">The multi instance factory.</param>
 public Mediator(SingleInstanceFactory singleInstanceFactory, MultiInstanceFactory multiInstanceFactory)
 {
     _singleInstanceFactory = singleInstanceFactory;
     _multiInstanceFactory  = multiInstanceFactory;
 }
コード例 #15
0
 public SchemaSerializerProvider(MultiInstanceFactory multiInstanceFactory)
 {
     _list = multiInstanceFactory(typeof(ISchemaSerializerFactory)).Cast <ISchemaSerializerFactory>().ToList();
 }
コード例 #16
0
 public abstract Task Handle(INotification notification, CancellationToken cancellationToken, IMediatorContext context, MultiInstanceFactory multiInstanceFactory, Func <IEnumerable <RequestHandlerDelegate <Unit> >, Task> publish);
コード例 #17
0
 public Bus(SingleInstanceFactory commandHandlerFactory, MultiInstanceFactory eventHandlersFactory)
 {
     this.commandHandlerFactory = commandHandlerFactory;
     this.eventHandlersFactory  = eventHandlersFactory;
 }
コード例 #18
0
        private static async Task GetPipeline(TNotification request, IMediatorContext context, IEnumerable <RequestHandlerDelegate <Unit> > handlers, MultiInstanceFactory factory, Func <IEnumerable <RequestHandlerDelegate <Unit> >, Task> publish)
        {
            var behaviors = factory(typeof(IPipelineBehavior <TNotification, Unit>))
                            .Cast <IPipelineBehavior <TNotification, Unit> >()
                            .Reverse()
                            .ToArray();

            var tasks = new List <RequestHandlerDelegate <Unit> >();

            foreach (var handle in handlers)
            {
                RequestHandlerDelegate <Unit> handleCoreDelegate = async() =>
                {
                    await handle();

                    return(Unit.Value);
                };
                var aggregate = behaviors.Aggregate(handleCoreDelegate, (next, pipeline) => () => pipeline.Handle(request, next, context));
                tasks.Add(aggregate);
            }

            await publish(tasks);
        }
コード例 #19
0
 public abstract Task HandleAsync(IEvent @event, CancellationToken cancellationToken,
                                  MultiInstanceFactory multiInstanceFactory,
                                  Func <IEnumerable <Task>, Task> publish);
コード例 #20
0
        private IEnumerable <RequestHandlerDelegate <Unit> > GetHandlers(TNotification notification, CancellationToken cancellationToken, IMediatorContext context, MultiInstanceFactory factory)
        {
            var notificationHandlers = GetHandlers <INotificationHandler <TNotification> >(factory)
                                       .Select(x =>
            {
                return(new RequestHandlerDelegate <Unit>(() =>
                {
                    x.Handle(notification);
                    return Task.FromResult(Unit.Value);
                }));
            });

            var asyncNotificationHandlers = GetHandlers <IAsyncNotificationHandler <TNotification> >(factory)
                                            .Select(x =>
            {
                return(new RequestHandlerDelegate <Unit>(async() =>
                {
                    await x.Handle(notification).ConfigureAwait(false);
                    return Unit.Value;
                }));
            });

            var cancellableAsyncNotificationHandlers = GetHandlers <ICancellableAsyncNotificationHandler <TNotification> >(factory)
                                                       .Select(x =>
            {
                return(new RequestHandlerDelegate <Unit>(async() =>
                {
                    await x.Handle(notification, cancellationToken).ConfigureAwait(false);
                    return Unit.Value;
                }));
            });

            var contextualAsyncNotificationHandlers = GetHandlers <IContextualAsyncNotificationHandler <TNotification> >(factory)
                                                      .Select(x =>
            {
                return(new RequestHandlerDelegate <Unit>(async() =>
                {
                    await x.Handle(notification, context).ConfigureAwait(false);
                    return Unit.Value;
                }));
            });

            var allHandlers = notificationHandlers
                              .Concat(asyncNotificationHandlers)
                              .Concat(cancellableAsyncNotificationHandlers)
                              .Concat(contextualAsyncNotificationHandlers);

            return(allHandlers);
        }
コード例 #21
0
ファイル: Bus.cs プロジェクト: ClearMeasureLabs/Battleship
 public Bus(SingleInstanceFactory singleInstanceFactory, MultiInstanceFactory multiInstanceFactory)
 {
     _singleInstanceFactory = singleInstanceFactory;
     _multiInstanceFactory  = multiInstanceFactory;
 }
コード例 #22
0
 public BeaverMediator(SingleInstanceFactory single, MultiInstanceFactory multi, ILogger <BeaverMediator> logger)
 {
     _logger = logger;
     _inner  = new Mediator(single, multi);
 }
コード例 #23
0
 public abstract Task Handle(INotification notification, CancellationToken cancellationToken, MultiInstanceFactory multiInstanceFactory, Func <IEnumerable <Task>, Task> publish);
コード例 #24
0
ファイル: CommandHandler.cs プロジェクト: pmdevers/Servicebus
 public abstract Task HandleAsync(ICommand command, CancellationToken cancellationToken,
                                  SingleInstanceFactory singleFactory, MultiInstanceFactory multiFactory);
コード例 #25
0
        public override Task Handle(INotification notification, CancellationToken cancellationToken, MultiInstanceFactory multiInstanceFactory, Func <IEnumerable <Task>, Task> publish)
        {
            var handlers = multiInstanceFactory(typeof(INotificationHandler <TNotification>))
                           .Cast <INotificationHandler <TNotification> >()
                           .Select(x => x.Handle((TNotification)notification, cancellationToken));

            return(publish(handlers));
        }
コード例 #26
0
 public ServiceLocator(IResolver resolver)
 {
     _resolver             = resolver;
     SingleInstanceFactory = GetInstance;
     MultiInstanceFactory  = GetAllInstances;
 }
コード例 #27
0
 public Factory(MultiInstanceFactory multiInstanceFactory, SingleInstanceFactory singleInstanceFactory)
 {
     _multiInstanceFactory  = multiInstanceFactory;
     _singleInstanceFactory = singleInstanceFactory;
 }
コード例 #28
0
ファイル: RequestHandler.cs プロジェクト: shadowca/MediatR
 public abstract Task Handle(IRequest request, CancellationToken cancellationToken,
                             SingleInstanceFactory singleFactory, MultiInstanceFactory multiFactory);
コード例 #29
0
 public ServiceBus(SingleInstanceFactory singleInstanceFactory, MultiInstanceFactory multiInstanceFactory)
 {
     _singleInstanceFactory = singleInstanceFactory ?? throw new ArgumentNullException(nameof(singleInstanceFactory));
     _multiInstanceFactory  = multiInstanceFactory ?? throw new ArgumentNullException(nameof(multiInstanceFactory));
 }