/// <summary>
        /// Configure a pipeline for specific event type
        /// </summary>
        /// <param name="configurator">Events pipeline configurator</param>
        /// <param name="configure">Delegate for configure pipeline</param>
        /// <typeparam name="TEvent">Event type</typeparam>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="configure"/> is null</exception>
        public static void UseForEvent <TEvent>(
            this IPipeConfigurator <IEventHandlingContext> configurator,
            Action <IPipeConfigurator <IEventHandlingContext <TEvent> > > configure)
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            configurator.UseRouteFor(
                context => context is IEventHandlingContext <TEvent>,
                configure);
        }
        /// <summary>
        /// Configure a pipeline for specific command type
        /// </summary>
        /// <param name="configurator">Commands pipeline configurator</param>
        /// <param name="configure">Delegate for configure pipeline</param>
        /// <typeparam name="TCommand">Command type</typeparam>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="configure"/> is null</exception>
        public static void UseForCommand <TCommand>(
            this IPipeConfigurator <ICommandHandlingContext> configurator,
            Action <IPipeConfigurator <ICommandHandlingContext <TCommand> > > configure)
            where TCommand : ICommand
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            configurator.UseRouteFor(
                context => context is ICommandHandlingContext <TCommand>,
                configure);
        }
Example #3
0
        /// <summary>
        /// Configure a pipeline for specific query type
        /// </summary>
        /// <param name="configurator">Queries pipeline configurator</param>
        /// <param name="configure">Delegate for configure pipeline</param>
        /// <typeparam name="TQuery">Query type</typeparam>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="configure"/> is null</exception>
        public static void UseForQuery <TQuery>(
            this IPipeConfigurator <IQueryHandlingContext> configurator,
            Action <IPipeConfigurator <IQueryHandlingContext <TQuery> > > configure)
            where TQuery : IQuery
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            configurator.UseRouteFor(
                context => context is IQueryHandlingContext <TQuery>,
                configure);
        }
        /// <summary>
        /// Configuring a pipeline for command types
        /// </summary>
        /// <param name="configurator">Commands pipeline configurator</param>
        /// <param name="commandTypes">Command types</param>
        /// <param name="configure">Delegate for configure pipeline</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="configure"/> or <paramref name="commandTypes"/> is null</exception>
        public static void UseForCommands(
            this IPipeConfigurator <ICommandHandlingContext> configurator,
            HashSet <Type> commandTypes,
            Action <IPipeConfigurator <ICommandHandlingContext> > configure)
        {
            if (commandTypes == null)
            {
                throw new ArgumentNullException(nameof(commandTypes));
            }

            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            configurator.UseRouteFor(
                context => commandTypes.Contains(context.Command.GetType()),
                configure);
        }
        /// <summary>
        /// Configuring a pipeline for commands matched a predicate
        /// </summary>
        /// <param name="configurator">Commands pipeline configurator</param>
        /// <param name="predicate">Command match predicate</param>
        /// <param name="configure">Delegate for configure pipeline</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="configure"/> or <paramref name="predicate"/> is null</exception>
        public static void UseForCommands(
            this IPipeConfigurator <ICommandHandlingContext> configurator,
            Func <ICommand, bool> predicate,
            Action <IPipeConfigurator <ICommandHandlingContext> > configure)
        {
            if (predicate == null)
            {
                throw new ArgumentNullException(nameof(predicate));
            }

            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            configurator.UseRouteFor(
                context => predicate(context.Command),
                configure);
        }