Esempio n. 1
0
        /// <inheritdoc />
        public async Task <TResult> ProcessAsync <TResult>(ICommand <TResult> command, CancellationToken cancellationToken)
        {
            Ensure.Arg.NotNull(command, nameof(command));

            Type commandType = command.GetType();

            var pipeline =
                (ICommandPipeline <TResult>)CommandPipelineFactory.CreateCommandPipeline(commandType, _activator);

            CommandDescriptor commandDescriptor = _commandDescriptorFactory.CreateDescriptor(commandType);
            ICommandContext   commandContext    = pipeline.CreateCommandContext(commandDescriptor, command);

            if (_commandContextAccessor != null)
            {
                _commandContextAccessor.CommandContext = commandContext;
            }

            try
            {
                return(await pipeline.InvokeAsync(commandContext, cancellationToken)
                       .ConfigureAwait(false));
            }
            finally
            {
                if (_commandContextAccessor != null)
                {
                    _commandContextAccessor.CommandContext = null;
                }
            }
        }
Esempio n. 2
0
        public CommandPipelineFactoryShould()
        {
            _engine  = new Mock <IDependencyEngine>();
            _factory = new CommandPipelineFactory();

            _behaviourType     = typeof(ICommandBehaviour <Command>);
            _pipelineType      = typeof(ICommandPipeline <Command>);
            _preProcessorType  = typeof(ICommandPreProcessor <Command>);
            _postProcessorType = typeof(ICommandPostProcessor <Command>);
        }
Esempio n. 3
0
        internal static void UpsertPipeline(IServiceCollection services, Type contract, ServiceLifetime lifetime)
        {
            var commandType  = contract.GenericTypeArguments[0];
            var pipelineType = Types.CommandPipeline.MakeGenericType(commandType);

            if (services.RemoveLessLifetimeService(pipelineType, lifetime, true))
            {
                services.Add(new ServiceDescriptor(
                                 pipelineType,
                                 CommandPipelineFactory.GetActivator(commandType),
                                 lifetime));
            }
        }