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

correlationIdAccessor ICorrelationIdAccessor

The ICorrelationIdAccessor to use for accessing correlation IDs.

commandFilters ICommandFilters

The ICommandFilters to use for filtering commands.

handlerProviders ICommandHandlerProviders

The ICommandHandlerProviders to use for finding command handlers.

valueHandlers ICommandResponseValueHandlers

The ICommandResponseValueHandlers to use for handling response values.

contextModifier ICommandContextModifier

The ICommandContextModifier to use for setting the current command context.

contextValuesBuilder ICommandContextValuesBuilder

The ICommandContextValuesBuilder to use for building command context values.

argumentResolver ICommandHandlerArgumentResolver

The ICommandHandlerArgumentResolver to use for resolving handler arguments.

executionScopes IInstancesOf<ICommandExecutionScope>

The discovered ICommandExecutionScope implementations that participate in every command's execution.

scopeFactory IServiceScopeFactory

The IServiceScopeFactory used to create a dedicated service scope when no IServiceProvider is provided.

activitySource IActivitySource<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

command object

The command to execute.

serviceProvider IServiceProvider

The IServiceProvider scoped to the current request, used to resolve handler dependencies.

allowedSeverity ValidationResultSeverity?

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

command object

The command to execute.

serviceProvider IServiceProvider

The IServiceProvider scoped to the current request, used to resolve handler dependencies.

allowedSeverity ValidationResultSeverity?

Optional maximum validation result severity level to allow.

cancellationToken CancellationToken

The 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

command object

The command to execute.

allowedSeverity ValidationResultSeverity?

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

command object

The command to execute.

allowedSeverity ValidationResultSeverity?

Optional maximum validation result severity level to allow.

cancellationToken CancellationToken

The 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

command object

The command to execute.

serviceProvider IServiceProvider

The IServiceProvider scoped to the current request, used to resolve handler dependencies.

allowedSeverity ValidationResultSeverity?

Optional maximum validation result severity level to allow.

Returns

Task<CommandResult<TResult>>

A CommandResult<TResponse> representing the result of executing the command.

Type Parameters

TResult

The 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

command object

The command to execute.

serviceProvider IServiceProvider

The IServiceProvider scoped to the current request, used to resolve handler dependencies.

allowedSeverity ValidationResultSeverity?

Optional maximum validation result severity level to allow.

cancellationToken CancellationToken

The cancellation token for the command execution.

Returns

Task<CommandResult<TResult>>

A CommandResult<TResponse> representing the result of executing the command.

Type Parameters

TResult

The 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

command object

The command to execute.

allowedSeverity ValidationResultSeverity?

Optional maximum validation result severity level to allow.

Returns

Task<CommandResult<TResult>>

A CommandResult<TResponse> representing the result of executing the command.

Type Parameters

TResult

The 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

command object

The command to execute.

allowedSeverity ValidationResultSeverity?

Optional maximum validation result severity level to allow.

cancellationToken CancellationToken

The cancellation token for the command execution.

Returns

Task<CommandResult<TResult>>

A CommandResult<TResponse> representing the result of executing the command.

Type Parameters

TResult

The 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

command object

The command to validate.

serviceProvider IServiceProvider

The IServiceProvider scoped to the current request, used to resolve handler dependencies.

allowedSeverity ValidationResultSeverity?

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

command object

The command to validate.

serviceProvider IServiceProvider

The IServiceProvider scoped to the current request, used to resolve handler dependencies.

allowedSeverity ValidationResultSeverity?

Optional maximum validation result severity level to allow.

cancellationToken CancellationToken

The 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

command object

The command to validate.

allowedSeverity ValidationResultSeverity?

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

command object

The command to validate.

allowedSeverity ValidationResultSeverity?

Optional maximum validation result severity level to allow.

cancellationToken CancellationToken

The cancellation token for the command validation.

Returns

Task<CommandResult>

A CommandResult representing the validation result.