/// <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; } } }
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>); }
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)); } }