Open zinov opened 8 months ago
First I am not from clean architecture team, But is this issue related to this clean architecture project template. My recommendation is try set up FluentValidation
in separate project. Feel like your issue is related to AddFluentValidationFromAssembly
.
I assume the validation in your case is not being hit because the ValidationBehaviour
specifically only validates the classes implementing the interface: where TRequest : IRequest<TResponse>
Why it's not being validated at controller level - that is a separate issue.
Describe the bug I am trying to set up a Validator associated with my query parameters, which are wrapped inside a class and marked as [FromQuery] inside of the action method of the controller.
My Controller looks like this one:
public async Task<ActionResult> GetVehicles([FromQuery] VehicleRequestDto requestDto)
My Dto:
my validator validator
Keeping the AddFluentValidationFromAssembly(...)
but it never hits the validator before hitting the controller, also in the ValidationBehaviour I am not getting any validators
To Reproduce Steps to reproduce the behavior:
Create a Dto public class VehicleRequestDto { public int PageNumber { get; set; } }
Create a Validator for the Dto instead of the query handler and try to call the endpoint
It hits the controller endpoint but never triggers the validator or passes any validators to the ValidationBehaviour to get executed. Also, check that ValidationBehaviour is executing an async call to ValidateAsync when the .net core pipeline is sync.
Please also check and reconsider removing the library from the solution and use manual validation instead, eventually if this is the case, I think the ValidationBehaviour is going to go away.
https://github.com/FluentValidation/FluentValidation/issues/1959 https://github.com/dotnet/aspnetcore/issues/31905