Automatically use Command Valdiators
robinmanuelthiel opened this issue · comments
Currently, when validating a command, we need to do that manually:
public async Task<Void> HandleAsync(UpdateSpaceBlocksDeploymentConfigCommand command)
{
var validator = new UpdateSpaceBlocksDeploymentConfigCommandValidator();
validator.Validate(command);
// ...
}
It would be nice, if command validators would be registered in the system (preferraby via annotation) as well and commands would automatically be validated in the command handler.
Also, when and how to use Command Validators needs to be added to the docs here: https://docs-internal.wemogy.com/libs/cqrs/commands#command-validation
What do you think @SebastianKuesters
Just saw, that a FluentValidationCommandValidator<T>
will already be injected automatically, is that correct? If so, I think we just need to document that and can then close this.
We use CommandValidators at a few places already. The usage is also documented in the link you mentioned: https://docs-internal.wemogy.com/libs/cqrs/commands#custom-implementation
Maybe there is an issue in the way how you try to use it? Let's check it out in a call.