示例#1
0
 public PriceCalculator(IEventHandlerCollection eventHandlers, IQueryDispatcher queryDispatcher)
 {
     Ensure.NotNull(eventHandlers, "eventHandlers");
     Ensure.NotNull(queryDispatcher, "queryDispatcher");
     eventHandlers.AddAll(this);
     this.queryDispatcher = queryDispatcher;
 }
示例#2
0
 public CurrencyCache(IEventHandlerCollection eventHandlers, IQueryHandlerCollection queryHandlers)
 {
     Ensure.NotNull(eventHandlers, "eventHandlers");
     Ensure.NotNull(queryHandlers, "queryHandlers");
     eventHandlers.AddAll(this);
     queryHandlers.AddAll(this);
 }
示例#3
0
        public static UiThreadEventHandler <T> AddUiThread <T>(this IEventHandlerCollection handlers, IEventHandler <T> handler, CoreDispatcher synchronizer)
        {
            Ensure.NotNull(handlers, "handlers");
            UiThreadEventHandler <T> threadHandler = new UiThreadEventHandler <T>(handler, synchronizer);

            handlers.Add <T>(threadHandler);
            return(threadHandler);
        }
示例#4
0
 public ApiHub(IEventHandlerCollection eventHandlers, FormatterContainer formatters, ExceptionHandlerBuilder exceptionHandlerBuilder)
 {
     Ensure.NotNull(eventHandlers, "eventHandlers");
     Ensure.NotNull(formatters, "formatters");
     this.formatters = formatters;
     eventHandlers.AddAll(this);
     exceptionHandlerBuilder.Filter <AggregateRootException>().Handler(this);
 }
示例#5
0
 /// <summary>
 /// Creates context from event data envelope.
 /// </summary>
 /// <param name="payload">Event data wrapped in envelope.</param>
 /// <param name="handlers">Current collection of event subscriptions.</param>
 /// <param name="dispatcher">Current event dispatcher.</param>
 public DefaultEventHandlerContext(Envelope <TEvent> payload, IEventHandlerCollection handlers, IEventDispatcher dispatcher)
 {
     Ensure.NotNull(payload, "payload");
     Ensure.NotNull(handlers, "eventHandlers");
     Ensure.NotNull(dispatcher, "dispatcher");
     Payload    = payload;
     Handlers   = handlers;
     Dispatcher = dispatcher;
 }
示例#6
0
 public CurrencyCache(IEventHandlerCollection eventHandlers, IQueryHandlerCollection queryHandlers, IQueryDispatcher queryDispatcher)
 {
     Ensure.NotNull(eventHandlers, "eventHandlers");
     Ensure.NotNull(queryHandlers, "queryHandlers");
     Ensure.NotNull(queryDispatcher, "queryDispatcher");
     eventHandlers.AddAll(this);
     queryHandlers.AddAll(this);
     this.queryDispatcher = queryDispatcher;
 }
示例#7
0
 public BootstrapTask(IQueryHandlerCollection queryHandlers, IEventHandlerCollection eventHandlers, IFactory <ReadModelContext> dbFactory, IPriceConverter priceConverter)
 {
     Ensure.NotNull(queryHandlers, "queryHandlers");
     Ensure.NotNull(eventHandlers, "eventHandlers");
     Ensure.NotNull(dbFactory, "dbFactory");
     Ensure.NotNull(priceConverter, "priceConverter");
     this.queryHandlers  = queryHandlers;
     this.eventHandlers  = eventHandlers;
     this.dbFactory      = dbFactory;
     this.priceConverter = priceConverter;
 }
        /// <summary>
        /// Returns continuation task that is completed when <paramref name="eventHandlers"/> gets
        /// notification for event of the type <typeparamref name="T"/> and <paramref name="filter"/> is satisfied.
        /// </summary>
        /// <typeparam name="T">The type of the event (can contain <see cref="Envelope"/> or <see cref="IEventHandlerContext{T}"/>).</typeparam>
        /// <param name="eventHandlers">The collection of an event handlers.</param>
        /// <param name="filter">The event filter, only the event for which returns true is used to complete the task.</param>
        /// <param name="token">The continuation task cancellation token.</param>
        /// <returns>
        /// Continuation task that is completed when <paramref name="eventHandlers"/> gets
        /// notification for event of the type <typeparamref name="T"/> and <paramref name="filter"/> is satisfied.
        /// </returns>
        public static Task <T> Await <T>(this IEventHandlerCollection eventHandlers, Func <T, bool> filter, CancellationToken token)
        {
            Ensure.NotNull(eventHandlers, "eventHandlers");
            Ensure.NotNull(filter, "filter");
            Ensure.NotNull(token, "token");

            TaskCompletionSource <T> source = new TaskCompletionSource <T>();

            eventHandlers.Add(new AwaitEventHandler <T>(eventHandlers, source, token, filter));

            return(source.Task);
        }
示例#9
0
        private void QueryMiddlewares(IEventHandlerCollection handlers)
        {
            void AddMiddlewareAndEventHandler <T>(T handler)
                where T : HttpQueryDispatcher.IMiddleware
            {
                handlers.AddAll(handler);
                services.AddSingleton <HttpQueryDispatcher.IMiddleware>(handler);
            }

            AddMiddlewareAndEventHandler(new CategoryMiddleware());
            AddMiddlewareAndEventHandler(new CurrencyMiddleware());
            AddMiddlewareAndEventHandler(new UserMiddleware());
        }
示例#10
0
        private void QueryMiddlewares(IEventHandlerCollection handlers)
        {
            CategoryMiddleware categoryMiddleware = new CategoryMiddleware();
            CurrencyMiddleware currencyMiddleware = new CurrencyMiddleware();

            handlers
            .AddAll(categoryMiddleware)
            .AddAll(currencyMiddleware);

            services
            .AddSingleton <HttpQueryDispatcher.IMiddleware>(categoryMiddleware)
            .AddSingleton <HttpQueryDispatcher.IMiddleware>(currencyMiddleware);
        }
            public AwaitEventHandler(IEventHandlerCollection collection, TaskCompletionSource <T> source, CancellationToken cancellation, Func <T, bool> filter)
            {
                Ensure.NotNull(collection, "collection");
                Ensure.NotNull(source, "source");
                Ensure.NotNull(cancellation, "cancellation");
                Ensure.NotNull(filter, "filter");
                this.collection   = collection;
                this.source       = source;
                this.cancellation = cancellation;
                this.filter       = filter;

                cancellation.Register(OnCancellationRequested);
            }
        /// <summary>
        /// Registers <paramref name="handler"/> to handle events for all implemented interfaces <see cref="IEventHandler{T}"/>.
        /// </summary>
        /// <param name="collection">The collection of events handlers.</param>
        /// <param name="handler">The event handler.</param>
        /// <returns><paramref name="collection"/>.</returns>
        public static IEventHandlerCollection AddAll(this IEventHandlerCollection collection, object handler)
        {
            Ensure.NotNull(collection, "collection");
            Ensure.NotNull(handler, "handler");
            foreach (Type interfaceType in handler.GetType().GetInterfaces())
            {
                if (interfaceType.IsGenericType && typeof(IEventHandler <>) == interfaceType.GetGenericTypeDefinition())
                {
                    MethodInfo addMethod = collection.GetType().GetMethod(Constant.EventHandlerCollectionAddMethodName).MakeGenericMethod(interfaceType.GetGenericArguments());
                    addMethod.Invoke(collection, new object[] { handler });
                }
            }

            return(collection);
        }
 /// <summary>
 /// Returns continuation task that is completed when <paramref name="eventHandlers"/> gets
 /// notification for event of the type <typeparamref name="T"/> and <paramref name="filter"/> is satisfied.
 /// </summary>
 /// <typeparam name="T">The type of the event (can contain <see cref="Envelope"/> or <see cref="IEventHandlerContext{T}"/>).</typeparam>
 /// <param name="eventHandlers">The collection of an event handlers.</param>
 /// <param name="filter">The event filter, only the event for which returns true is used to complete the task.</param>
 /// <returns>
 /// Continuation task that is completed when <paramref name="eventHandlers"/> gets
 /// notification for event of the type <typeparamref name="T"/> and <paramref name="filter"/> is satisfied.
 /// </returns>
 public static Task <T> Await <T>(this IEventHandlerCollection eventHandlers, Func <T, bool> filter)
 {
     return(Await(eventHandlers, filter, CancellationToken.None));
 }
示例#14
0
 public PriceCalculator(IEventHandlerCollection eventHandlers)
 {
     Ensure.NotNull(eventHandlers, "eventHandlers");
     eventHandlers.AddAll(this);
 }
示例#15
0
 /// <summary>
 /// Creates context from event data and wraps it into <see cref="Envelope{TEvent}"/>.
 /// </summary>
 /// <param name="payload">Event data.</param>
 /// <param name="handlers">Current collection of event subscriptions.</param>
 /// <param name="dispatcher">Current event dispatcher.</param>
 public DefaultEventHandlerContext(TEvent payload, IEventHandlerCollection handlers, IEventDispatcher dispatcher)
     : this(Envelope.Create(payload), handlers, dispatcher)
 {
 }
示例#16
0
 public abstract void Remove(IEventHandlerCollection handlers);
示例#17
0
 public abstract void Add(IEventHandlerCollection handlers);
 /// <summary>
 /// Returns continuation task that is completed when <paramref name="eventHandlers"/> gets
 /// notification for event of the type <typeparamref name="T"/>.
 /// </summary>
 /// <typeparam name="T">The type of the event (can contain <see cref="Envelope"/> or <see cref="IEventHandlerContext{T}"/>).</typeparam>
 /// <param name="eventHandlers">The collection of an event handlers.</param>
 /// <returns>
 /// Continuation task that is completed when <paramref name="eventHandlers"/> gets
 /// notification for event of the type <typeparamref name="T"/>.
 /// </returns>
 public static Task <T> Await <T>(this IEventHandlerCollection eventHandlers)
 {
     return(Await <T>(eventHandlers, CancellationToken.None));
 }
 /// <summary>
 /// Returns continuation task that is completed when <paramref name="eventHandlers"/> gets
 /// notification for event of the type <typeparamref name="T"/>.
 /// </summary>
 /// <typeparam name="T">The type of the event (can contain <see cref="Envelope"/> or <see cref="IEventHandlerContext{T}"/>).</typeparam>
 /// <param name="eventHandlers">The collection of an event handlers.</param>
 /// <param name="token">The continuation task cancellation token.</param>
 /// <returns>
 /// Continuation task that is completed when <paramref name="eventHandlers"/> gets
 /// notification for event of the type <typeparamref name="T"/>.
 /// </returns>
 public static Task <T> Await <T>(this IEventHandlerCollection eventHandlers, CancellationToken token)
 {
     return(Await <T>(eventHandlers, e => true, token));
 }