Class CommandPipeline
- Namespace
- Cratis.Arc.Commands
- Assembly
- Cratis.Arc.Core.dll
Represents an implementation of ICommandPipeline.
[Singleton]
public class CommandPipeline : ICommandPipelineWithCancellation, ICommandPipeline
- Inheritance
-
CommandPipeline
- Implements
- Inherited Members
- Extension Methods
Constructors
CommandPipeline(ICorrelationIdAccessor, ICommandFilters, ICommandHandlerProviders, ICommandResponseValueHandlers, ICommandContextModifier, ICommandContextValuesBuilder, ICommandHandlerArgumentResolver, IInstancesOf<ICommandExecutionScope>, IServiceScopeFactory, IActivitySource<CommandPipeline>)
Represents an implementation of ICommandPipeline.
public CommandPipeline(ICorrelationIdAccessor correlationIdAccessor, ICommandFilters commandFilters, ICommandHandlerProviders handlerProviders, ICommandResponseValueHandlers valueHandlers, ICommandContextModifier contextModifier, ICommandContextValuesBuilder contextValuesBuilder, ICommandHandlerArgumentResolver argumentResolver, IInstancesOf<ICommandExecutionScope> executionScopes, IServiceScopeFactory scopeFactory, IActivitySource<CommandPipeline> activitySource)
Parameters
correlationIdAccessorICorrelationIdAccessorThe ICorrelationIdAccessor to use for accessing correlation IDs.
commandFiltersICommandFiltersThe ICommandFilters to use for filtering commands.
handlerProvidersICommandHandlerProvidersThe ICommandHandlerProviders to use for finding command handlers.
valueHandlersICommandResponseValueHandlersThe ICommandResponseValueHandlers to use for handling response values.
contextModifierICommandContextModifierThe ICommandContextModifier to use for setting the current command context.
contextValuesBuilderICommandContextValuesBuilderThe ICommandContextValuesBuilder to use for building command context values.
argumentResolverICommandHandlerArgumentResolverThe ICommandHandlerArgumentResolver to use for resolving handler arguments.
executionScopesIInstancesOf<ICommandExecutionScope>The discovered ICommandExecutionScope implementations that participate in every command's execution.
scopeFactoryIServiceScopeFactoryThe IServiceScopeFactory used to create a dedicated service scope when no IServiceProvider is provided.
activitySourceIActivitySource<CommandPipeline>The IActivitySource<T> for tracing.
Methods
Execute(object, IServiceProvider, ValidationResultSeverity?)
Executes the given command within the provided service scope.
public Task<CommandResult> Execute(object command, IServiceProvider serviceProvider, ValidationResultSeverity? allowedSeverity = null)
Parameters
commandobjectThe command to execute.
serviceProviderIServiceProviderThe IServiceProvider scoped to the current request, used to resolve handler dependencies.
allowedSeverityValidationResultSeverity?Optional maximum validation result severity level to allow.
Returns
- Task<CommandResult>
A CommandResult representing the result of executing the command.
Execute(object, IServiceProvider, ValidationResultSeverity?, CancellationToken)
Executes the given command within the provided service scope.
public Task<CommandResult> Execute(object command, IServiceProvider serviceProvider, ValidationResultSeverity? allowedSeverity, CancellationToken cancellationToken)
Parameters
commandobjectThe command to execute.
serviceProviderIServiceProviderThe IServiceProvider scoped to the current request, used to resolve handler dependencies.
allowedSeverityValidationResultSeverity?Optional maximum validation result severity level to allow.
cancellationTokenCancellationTokenThe cancellation token for the command execution.
Returns
- Task<CommandResult>
A CommandResult representing the result of executing the command.
Execute(object, ValidationResultSeverity?)
Executes the given command, creating a dedicated service scope for dependency resolution.
public Task<CommandResult> Execute(object command, ValidationResultSeverity? allowedSeverity = null)
Parameters
commandobjectThe command to execute.
allowedSeverityValidationResultSeverity?Optional maximum validation result severity level to allow.
Returns
- Task<CommandResult>
A CommandResult representing the result of executing the command.
Execute(object, ValidationResultSeverity?, CancellationToken)
Executes the given command, creating a dedicated service scope for dependency resolution.
public Task<CommandResult> Execute(object command, ValidationResultSeverity? allowedSeverity, CancellationToken cancellationToken)
Parameters
commandobjectThe command to execute.
allowedSeverityValidationResultSeverity?Optional maximum validation result severity level to allow.
cancellationTokenCancellationTokenThe cancellation token for the command execution.
Returns
- Task<CommandResult>
A CommandResult representing the result of executing the command.
Execute<TResult>(object, IServiceProvider, ValidationResultSeverity?)
Executes the given command and returns a strongly-typed result within the provided service scope.
public Task<CommandResult<TResult>> Execute<TResult>(object command, IServiceProvider serviceProvider, ValidationResultSeverity? allowedSeverity = null)
Parameters
commandobjectThe command to execute.
serviceProviderIServiceProviderThe IServiceProvider scoped to the current request, used to resolve handler dependencies.
allowedSeverityValidationResultSeverity?Optional maximum validation result severity level to allow.
Returns
- Task<CommandResult<TResult>>
A CommandResult<TResponse> representing the result of executing the command.
Type Parameters
TResultThe type of the response returned by the command handler.
Remarks
If the handler returns a response of a different type than TResult, an InvalidCastException is thrown.
If the handler returns no response, or the command fails (authorization, validation, exception, no handler), the result is returned with Response set to default.
Execute<TResult>(object, IServiceProvider, ValidationResultSeverity?, CancellationToken)
Executes the given command and returns a strongly-typed result within the provided service scope.
public Task<CommandResult<TResult>> Execute<TResult>(object command, IServiceProvider serviceProvider, ValidationResultSeverity? allowedSeverity, CancellationToken cancellationToken)
Parameters
commandobjectThe command to execute.
serviceProviderIServiceProviderThe IServiceProvider scoped to the current request, used to resolve handler dependencies.
allowedSeverityValidationResultSeverity?Optional maximum validation result severity level to allow.
cancellationTokenCancellationTokenThe cancellation token for the command execution.
Returns
- Task<CommandResult<TResult>>
A CommandResult<TResponse> representing the result of executing the command.
Type Parameters
TResultThe type of the response returned by the command handler.
Execute<TResult>(object, ValidationResultSeverity?)
Executes the given command and returns a strongly-typed result, creating a dedicated service scope for dependency resolution.
public Task<CommandResult<TResult>> Execute<TResult>(object command, ValidationResultSeverity? allowedSeverity = null)
Parameters
commandobjectThe command to execute.
allowedSeverityValidationResultSeverity?Optional maximum validation result severity level to allow.
Returns
- Task<CommandResult<TResult>>
A CommandResult<TResponse> representing the result of executing the command.
Type Parameters
TResultThe type of the response returned by the command handler.
Remarks
If the handler returns a response of a different type than TResult, an InvalidCastException is thrown.
If the handler returns no response, or the command fails (authorization, validation, exception, no handler), the result is returned with Response set to default.
Execute<TResult>(object, ValidationResultSeverity?, CancellationToken)
Executes the given command and returns a strongly-typed result, creating a dedicated service scope for dependency resolution.
public Task<CommandResult<TResult>> Execute<TResult>(object command, ValidationResultSeverity? allowedSeverity, CancellationToken cancellationToken)
Parameters
commandobjectThe command to execute.
allowedSeverityValidationResultSeverity?Optional maximum validation result severity level to allow.
cancellationTokenCancellationTokenThe cancellation token for the command execution.
Returns
- Task<CommandResult<TResult>>
A CommandResult<TResponse> representing the result of executing the command.
Type Parameters
TResultThe type of the response returned by the command handler.
Validate(object, IServiceProvider, ValidationResultSeverity?)
Validates the given command without executing it, within the provided service scope.
public Task<CommandResult> Validate(object command, IServiceProvider serviceProvider, ValidationResultSeverity? allowedSeverity = null)
Parameters
commandobjectThe command to validate.
serviceProviderIServiceProviderThe IServiceProvider scoped to the current request, used to resolve handler dependencies.
allowedSeverityValidationResultSeverity?Optional maximum validation result severity level to allow.
Returns
- Task<CommandResult>
A CommandResult representing the validation result.
Remarks
This method runs authorization and validation filters but does not invoke the command handler. Use this for pre-flight validation before executing a command.
Validate(object, IServiceProvider, ValidationResultSeverity?, CancellationToken)
Validates the given command without executing it, within the provided service scope.
public Task<CommandResult> Validate(object command, IServiceProvider serviceProvider, ValidationResultSeverity? allowedSeverity, CancellationToken cancellationToken)
Parameters
commandobjectThe command to validate.
serviceProviderIServiceProviderThe IServiceProvider scoped to the current request, used to resolve handler dependencies.
allowedSeverityValidationResultSeverity?Optional maximum validation result severity level to allow.
cancellationTokenCancellationTokenThe cancellation token for the command validation.
Returns
- Task<CommandResult>
A CommandResult representing the validation result.
Validate(object, ValidationResultSeverity?)
Validates the given command without executing it, creating a dedicated service scope for dependency resolution.
public Task<CommandResult> Validate(object command, ValidationResultSeverity? allowedSeverity = null)
Parameters
commandobjectThe command to validate.
allowedSeverityValidationResultSeverity?Optional maximum validation result severity level to allow.
Returns
- Task<CommandResult>
A CommandResult representing the validation result.
Remarks
This method runs authorization and validation filters but does not invoke the command handler. Use this for pre-flight validation before executing a command.
Validate(object, ValidationResultSeverity?, CancellationToken)
Validates the given command without executing it, creating a dedicated service scope for dependency resolution.
public Task<CommandResult> Validate(object command, ValidationResultSeverity? allowedSeverity, CancellationToken cancellationToken)
Parameters
commandobjectThe command to validate.
allowedSeverityValidationResultSeverity?Optional maximum validation result severity level to allow.
cancellationTokenCancellationTokenThe cancellation token for the command validation.
Returns
- Task<CommandResult>
A CommandResult representing the validation result.