Class ValidatorInvoker
- Namespace
- Cratis.Arc.Validation
- Assembly
- Cratis.Arc.Core.dll
Represents an implementation of IValidatorInvoker for FluentValidation.
[Singleton]
public class ValidatorInvoker : IValidatorInvoker
- Inheritance
-
ValidatorInvoker
- Implements
- Inherited Members
- Extension Methods
Constructors
ValidatorInvoker(ILogger<ValidatorInvoker>)
Represents an implementation of IValidatorInvoker for FluentValidation.
public ValidatorInvoker(ILogger<ValidatorInvoker> logger)
Parameters
loggerILogger<ValidatorInvoker>The ILogger<TCategoryName> used to log a validator that throws while validating.
Fields
CouldNotValidateMessage
The message surfaced when a validator throws while validating.
public const string CouldNotValidateMessage = "The value could not be validated."
Field Value
Remarks
Deliberately says nothing about what went wrong: a validator throws on hostile or partial input, and the detail is logged server-side rather than handed back to whoever sent it. It reads the same for a command and for a query because the distinction tells a client nothing it can act on.
Methods
Invoke(object, IValidator, string, CancellationToken)
Runs a validator against an instance.
public Task<IEnumerable<ValidationResult>> Invoke(object instance, IValidator validator, string path, CancellationToken cancellationToken = default)
Parameters
instanceobjectThe instance to validate.
validatorIValidatorThe FluentValidation.IValidator to run.
pathstringThe camelCased member path from the graph root to
instance, empty at the root.cancellationTokenCancellationTokenOptional CancellationToken for cancelling the validation.
Returns
- Task<IEnumerable<ValidationResult>>
The ValidationResult collection describing the outcome, empty when valid.