0

I am trying to use fluentvalidation in my WebAPI projects for an asynchronous rules validations (e.g. check username duplication). (respecting the avoidance of manual use inside controllers, I want to validating before accessing the controller)

The documentation provided by the library saying that: You should not use asynchronous rules when using automatic validation with ASP.NET as ASP.NET’s validation pipeline is not asynchronous. If you use asynchronous rules with ASP.NET’s automatic validation, they will always be run synchronously.

I know it is possible to use manually the validation from the controller. However, I feel it breaks the clean architecture and coding convention in my App. I am trying to keep controllers free from any type of validation and I found it easy when validation does not necessitate database access. However, the need for rules validation Asynchronously will change the situation.

To Sum up:

  • I need to validate some rules asynchronously for some BM(s)

  • Documentary advise to use it manually and avoid using auto validation pipeline

  • I don't want to validateAsync inside the controller

  • Do you think the utilization of interceptor will make a sense?

AbuDawood
  • 745
  • 7
  • 22
  • What kind of architecture are you using? Business validation should happen basically on your business layer. – imnotaduck Sep 10 '19 at 04:14
  • Thank you for the pass, please note I am more interested to use fluentvalidation in an async way and before the reach controller action – AbuDawood Sep 10 '19 at 07:15
  • how about [https://stackoverflow.com/questions/9511462/run-a-method-in-each-request-in-mvc-c](https://stackoverflow.com/questions/9511462/run-a-method-in-each-request-in-mvc-c) and [https://stackoverflow.com/questions/26298356/execute-code-before-after-every-controller-action](https://stackoverflow.com/questions/26298356/execute-code-before-after-every-controller-action)? – imnotaduck Sep 10 '19 at 10:00
  • Use a custom action filter. – Arad Alvand May 09 '23 at 16:57

0 Answers0