MediatR.Extensions.FluentValidation.AspNetCore icon indicating copy to clipboard operation
MediatR.Extensions.FluentValidation.AspNetCore copied to clipboard

Run validation in an async context to allow async rules in FluentValidation v11

Open killergege opened this issue 3 years ago • 1 comments

Is your feature request related to a problem? Please describe. Until now FluentValidation, async rules were silently run as synchronous, so they could be used. Since v11, it now throws an exception when an async rule is executed synchronously, a lot of our validators are now throwing exceptions when validating a command.

Describe the solution you'd like Very very quickly looking at the code, it looks like the Validate() is already running in an async context. So it should be possible to call ValidateAsync instead of Validate, allowing to use async rules without too much impact. Could it be possible to change the code to do that ?

killergege avatar May 13 '22 10:05 killergege

This PR fixes the issue on our projects.

I don't suggest that this is merged as-is as it might add an async overhead for projects that don't use async validation rules which might have performance impacts. Maybe add another pipeline for async and another extension method / option to choose which one to inject ?

killergege avatar May 13 '22 15:05 killergege

Hello, any updates on this?

hiddentn avatar May 22 '23 16:05 hiddentn

Resolved in new version https://github.com/GetoXs/MediatR.Extensions.FluentValidation.AspNetCore/releases/tag/5.0.0

Based on CleanArchitecture solution https://github.com/jasontaylordev/CleanArchitecture/blob/main/src/Application/Common/Behaviours/ValidationBehaviour.cs

GetoXs avatar Oct 14 '23 14:10 GetoXs