Table of Contents

Class ValidateCommandBehavior<TRequest, TResponse>

Namespace
Arbiter.CommandQuery.Behaviors
Assembly
Arbiter.CommandQuery.dll

Pipeline behavior that validates a command request before passing it to the next handler.

public class ValidateCommandBehavior<TRequest, TResponse> : PipelineBehaviorBase<TRequest, TResponse>, IPipelineBehavior<TRequest, TResponse> where TRequest : class, IRequest<TResponse>

Type Parameters

TRequest

The type of request being handled.

TResponse

The type of response from the handler.

Inheritance
PipelineBehaviorBase<TRequest, TResponse>
ValidateCommandBehavior<TRequest, TResponse>
Implements
IPipelineBehavior<TRequest, TResponse>
Inherited Members

Constructors

ValidateCommandBehavior(ILoggerFactory, IValidator<TRequest>?)

Initializes a new instance of the ValidateCommandBehavior<TRequest, TResponse> class.

public ValidateCommandBehavior(ILoggerFactory loggerFactory, IValidator<TRequest>? validator = null)

Parameters

loggerFactory ILoggerFactory

The logger factory to create an ILogger for this handler.

validator IValidator<TRequest>

The validator to use for the request. If null, validation is skipped.

Methods

Process(TRequest, RequestHandlerDelegate<TResponse>, CancellationToken)

Processes the request by validating it before invoking the next handler in the pipeline. Throws a DomainException if validation fails.

protected override ValueTask<TResponse?> Process(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)

Parameters

request TRequest

The incoming request to validate and process.

next RequestHandlerDelegate<TResponse>

Awaitable delegate for the next action in the pipeline.

cancellationToken CancellationToken

The cancellation token.

Returns

ValueTask<TResponse>

Awaitable task returning the TResponse if validation succeeds; otherwise, throws an exception.

Exceptions

ArgumentNullException

Thrown if request or next is null.

DomainException

Thrown if validation fails.