コード例 #1
0
        /// <summary>
        /// Sends the specified command. We expect only one handler. The command is handled synchronously.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="command">The command.</param>
        /// <exception cref="System.ArgumentException">
        /// </exception>
        public void Send <T>(T command) where T : class, IRequest
        {
            using (var builder = new PipelineBuilder <T>(subscriberRegistry, handlerFactory, logger))
            {
                var requestContext = requestContextFactory.Create();
                requestContext.Policies = policyRegistry;

                logger.InfoFormat("Building send pipeline for command: {0}", command.Id);
                var handlerChain = builder.Build(requestContext);

                var handlerCount = handlerChain.Count();

                logger.InfoFormat("Found {0} pipelines for command: {1} {2}", handlerCount, typeof(T), command.Id);
                if (handlerCount > 1)
                {
                    throw new ArgumentException(string.Format("More than one handler was found for the typeof command {0} - a command should only have one handler.", typeof(T)));
                }
                if (handlerCount == 0)
                {
                    throw new ArgumentException(string.Format("No command handler was found for the typeof command {0} - a command should have only one handler.", typeof(T)));
                }

                handlerChain.First().Handle(command);
            }
        }
コード例 #2
0
        /// <summary>
        /// Sends the specified command. We expect only one handler. The command is handled synchronously.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="command">The command.</param>
        /// <exception cref="System.ArgumentException">
        /// </exception>
        public void Send <T>(T command) where T : class, IRequest
        {
            if (_handlerFactory == null)
            {
                throw new InvalidOperationException("No handler factory defined.");
            }

            var requestContext = _requestContextFactory.Create();

            requestContext.Policies = _policyRegistry;

            using (var builder = new PipelineBuilder <T>(_subscriberRegistry, _handlerFactory))
            {
                _logger.Value.InfoFormat("Building send pipeline for command: {0} {1}", command.GetType(), command.Id);
                var handlerChain = builder.Build(requestContext);

                AssertValidSendPipeline(command, handlerChain.Count());

                handlerChain.First().Handle(command);
            }
        }
コード例 #3
0
        /// <summary>
        /// Sends the specified command. We expect only one handler. The command is handled synchronously.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="command">The command.</param>
        /// <exception cref="System.ArgumentException">
        /// </exception>
        public void Send <T>(T command) where T : class, IRequest
        {
            if (_handlerFactorySync == null)
            {
                throw new InvalidOperationException("No handler factory defined.");
            }

            var requestContext = _requestContextFactory.Create();

            requestContext.Policies        = _policyRegistry;
            requestContext.FeatureSwitches = _featureSwitchRegistry;

            using (var builder = new PipelineBuilder <T>(_subscriberRegistry, _handlerFactorySync, _inboxConfiguration))
            {
                s_logger.LogInformation("Building send pipeline for command: {CommandType} {Id}", command.GetType(), command.Id);
                var handlerChain = builder.Build(requestContext);

                AssertValidSendPipeline(command, handlerChain.Count());

                handlerChain.First().Handle(command);
            }
        }
コード例 #4
0
        public void Send <T>(T command) where T : class, IRequest
        {
            var builder        = new ChainofResponsibilityBuilder <T>(container);
            var requestContext = requestContextFactory.Create();
            var handlerChain   = builder.Build(requestContext);

            var handlerCount = handlerChain.Count();

            if (handlerCount > 1)
            {
                throw new ArgumentException(string.Format("More than one handler was found for the typeof command {0} - a command should only have one handler.", typeof(T)));
            }
            if (handlerCount == 0)
            {
                throw new ArgumentException(string.Format("No command handler was found for the typeof command {0} - a command should have only one handler.", typeof(T)));
            }

            handlerChain.First().Handle(command);
        }