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()); }
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)); }
/// <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 }) { }
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); }
private static IEnumerable <THandler> GetHandlers <THandler>(MultiInstanceFactory factory) { return(factory(typeof(THandler)).Cast <THandler>()); }
public SequentialMediator(SingleInstanceFactory singleInstanceFactory, MultiInstanceFactory multiInstanceFactory) : base(singleInstanceFactory, multiInstanceFactory) { }
public AppMediator(MultiInstanceFactory multiInstanceFactory, SingleInstanceFactory singleInstanceFactory, IHttpContextAccessor httpContextAccessor, IAppDataContext appDataContext) { _inner = new Mediator(singleInstanceFactory, multiInstanceFactory); _httpContextAccessor = httpContextAccessor; _appDataContext = appDataContext; }
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); }
public override Task Handle(IEvent @event, ReactiveObject state, MultiInstanceFactory factory) { var tasks = GetTasks(@event, state, factory); return(Task.WhenAll(tasks)); }
public SequentialMediator(SingleInstanceFactory single, MultiInstanceFactory multi) { innerMediator = new Mediator(single, multi); }
public abstract Task Handle(IEvent @event, ReactiveObject state, MultiInstanceFactory factory);
public Mediator(MultiInstanceFactory multiInstanceFactory, SingleInstanceFactory singleInstanceFactory) { _factory = new Factory(multiInstanceFactory, singleInstanceFactory); }
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); }
/// <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; }
public SchemaSerializerProvider(MultiInstanceFactory multiInstanceFactory) { _list = multiInstanceFactory(typeof(ISchemaSerializerFactory)).Cast <ISchemaSerializerFactory>().ToList(); }
public abstract Task Handle(INotification notification, CancellationToken cancellationToken, IMediatorContext context, MultiInstanceFactory multiInstanceFactory, Func <IEnumerable <RequestHandlerDelegate <Unit> >, Task> publish);
public Bus(SingleInstanceFactory commandHandlerFactory, MultiInstanceFactory eventHandlersFactory) { this.commandHandlerFactory = commandHandlerFactory; this.eventHandlersFactory = eventHandlersFactory; }
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); }
public abstract Task HandleAsync(IEvent @event, CancellationToken cancellationToken, MultiInstanceFactory multiInstanceFactory, Func <IEnumerable <Task>, Task> publish);
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); }
public Bus(SingleInstanceFactory singleInstanceFactory, MultiInstanceFactory multiInstanceFactory) { _singleInstanceFactory = singleInstanceFactory; _multiInstanceFactory = multiInstanceFactory; }
public BeaverMediator(SingleInstanceFactory single, MultiInstanceFactory multi, ILogger <BeaverMediator> logger) { _logger = logger; _inner = new Mediator(single, multi); }
public abstract Task Handle(INotification notification, CancellationToken cancellationToken, MultiInstanceFactory multiInstanceFactory, Func <IEnumerable <Task>, Task> publish);
public abstract Task HandleAsync(ICommand command, CancellationToken cancellationToken, SingleInstanceFactory singleFactory, MultiInstanceFactory multiFactory);
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)); }
public ServiceLocator(IResolver resolver) { _resolver = resolver; SingleInstanceFactory = GetInstance; MultiInstanceFactory = GetAllInstances; }
public Factory(MultiInstanceFactory multiInstanceFactory, SingleInstanceFactory singleInstanceFactory) { _multiInstanceFactory = multiInstanceFactory; _singleInstanceFactory = singleInstanceFactory; }
public abstract Task Handle(IRequest request, CancellationToken cancellationToken, SingleInstanceFactory singleFactory, MultiInstanceFactory multiFactory);
public ServiceBus(SingleInstanceFactory singleInstanceFactory, MultiInstanceFactory multiInstanceFactory) { _singleInstanceFactory = singleInstanceFactory ?? throw new ArgumentNullException(nameof(singleInstanceFactory)); _multiInstanceFactory = multiInstanceFactory ?? throw new ArgumentNullException(nameof(multiInstanceFactory)); }