Describe the bug
A class that inherit AbstractValidator class will execute twice when a class that implement IRequest interface put parameters of method of controller class.
The reason is first time it happens in FluentValidationModelValidatorProvider class and second time happens in RequestValidationBehavior class.
If my AbstractValidator class has things of long time checking(ex: access Database), it will spend much time, and I think there is no need to do twice.
To Reproduce
Steps to reproduce the behavior:
Remove [Authorize] from TodoListsController.
Start debugging the default CleanArchitecture project.
Set a breakpoint at BeUniqueTitle's method of CreateTodoListCommandValidator class
Using Swagger call /api/TodoLists
Observe the breakpoint will be executed twice.
Expected behavior
It should be only validated once in the same AbstractValidator.
I think FluentValidationModelValidatorProvider doesn't need to be called, because RequestValidationBehavior is real to throw new ValidationException but FluentValidationModelValidatorProvider is not.
Screenshots
Additional context
Currently, I will add below code in ConfigureServices of Startup, because I don't know how to correctly remove it and I didn't find AddFluentValidation has related option.
services.AddMvcOptions(options =>
{
// avoid AbstractValidator validate again in Controller ModelValidator
var fluentValidationModelValidatorProvider
= options.ModelValidatorProviders.FirstOrDefault(x => x.GetType().Name.Contains("FluentValidationModelValidatorProvider"));
if (fluentValidationModelValidatorProvider != null)
{
options.ModelValidatorProviders.Remove(fluentValidationModelValidatorProvider);
}
});
Describe the bug A class that inherit AbstractValidator class will execute twice when a class that implement IRequest interface put parameters of method of controller class.
The reason is first time it happens in FluentValidationModelValidatorProvider class and second time happens in RequestValidationBehavior class.
If my AbstractValidator class has things of long time checking(ex: access Database), it will spend much time, and I think there is no need to do twice.
To Reproduce Steps to reproduce the behavior:
Expected behavior
It should be only validated once in the same AbstractValidator.
I think FluentValidationModelValidatorProvider doesn't need to be called, because RequestValidationBehavior is real to throw new ValidationException but FluentValidationModelValidatorProvider is not.
Screenshots
Additional context Currently, I will add below code in ConfigureServices of Startup, because I don't know how to correctly remove it and I didn't find AddFluentValidation has related option.