fullstackhero / dotnet-starter-kit

Production Grade Cloud-Ready .NET 8 Starter Kit (Web API + Blazor Client) with Multitenancy Support, and Clean/Modular Architecture that saves roughly 200+ Development Hours! All Batteries Included.
https://fullstackhero.net/dotnet-webapi-boilerplate/
MIT License
5.19k stars 1.56k forks source link

Can't use async in request validators with latest version of FluentValidations #799

Closed dsolteszopyn closed 4 months ago

dsolteszopyn commented 1 year ago

Validator "CreateUserRequestValidator" can't be used with ASP.NET automatic validation as it contains asynchronous rules. ASP.NET's validation pipeline is not asynchronous and can't invoke asynchronous rules. Remove the asynchronous rules in order for this validator to run.

Steps to reproduce the behavior:

  1. save a new user

Expected behavior Validation should be successful if all rules are met.

martin-arapovic-typeqast commented 1 year ago

Hi @dsolteszopyn ,

You've probably updated to FluentValidation version 11.x, where they throwing exceptions if validation is integrated with ASP.NET. Check docs

You need to use FluentValidation version 10.x, for it to work with Async methods.

If this PR gets merged, using Async methods will work, because Validation will be triggered by MediatR...

For now try to use FluentValidation version 10, or move validation to a MediatR's pipeline behavior as shown in mentioned PR.

dsolteszopyn commented 1 year ago

I updated my code to use the new pattern, works as expected now :)


From: Martin Arapović @.> Sent: Tuesday, November 15, 2022 10:35:42 AM To: fullstackhero/dotnet-webapi-boilerplate @.> Cc: Soltesz, Danny @.>; Mention @.> Subject: Re: [fullstackhero/dotnet-webapi-boilerplate] Can't use async in request validators with latest version of FluentValidations (Issue #799)

[CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe]

Hi @dsolteszopynhttps://protect-us.mimecast.com/s/lmjbCG62OqtqAnBfQ4fZD?domain=github.com ,

You've probably updated to FluentValidation version 11.x, where they throwing exceptions if validation is integrated with ASP.NET. Check docshttps://protect-us.mimecast.com/s/B3syCBB2J0fA8qDtzoy-n?domain=docs.fluentvalidation.net

You need to use FluentValidation version 10.x, for it to work with Async methods.

If this PRhttps://protect-us.mimecast.com/s/U5oyCDk2LnTM3poi59vzr?domain=github.com gets merged, using Async methods will work, because Validation will be triggered by MediatR...

For now try to use FluentValidation version 10, or move validation to a MediatR's pipeline behavior as shown in mentioned PRhttps://protect-us.mimecast.com/s/U5oyCDk2LnTM3poi59vzr?domain=github.com.

— Reply to this email directly, view it on GitHubhttps://protect-us.mimecast.com/s/3tSJCER2Motnpylip_-0_?domain=github.com, or unsubscribehttps://protect-us.mimecast.com/s/YDTyCJ62gwtyKOBHva4l4?domain=github.com. You are receiving this because you were mentioned.Message ID: @.***>

xts-velkumars commented 1 year ago

@martin-arapovic-typeqast

Is this issue resolved ? I'm also facing same exception.

Do I need to downgrade to 10.4.0 from 11.2.2

dsolteszopyn commented 1 year ago

you either need to downgrade or update your code based upon the PR mentioned above

xts-velkumars commented 1 year ago

Thank you @dsolteszopyn,

Its working as excepted after I changed my code.

Can we excepts async validators in futures release ?