Using the FluentValidation Rule Set Feature in the Web API

I would like to use the FluentValidation function in a web API project because I don’t want to perform manual checks, so I use FluentValidationModelValidatorProvider.Configureto add FluentValidation to ModelValidatorProvidersso that I automatically check my models before submitting the action method.

Up to this point, everything is fine and working correctly, but what if I decide to use the rule set function? When it comes to automatic verification, the examples you see on the Internet use CustomizeValidatorAttributethis:

public ActionResul Something([CustomizeValidator(RuleSet = "RuleName")]MyModel myModel)

But the problem is that CustomizeValidator is only available for ASP.NET MVC, so what should I do to have at least the same behavior in the web API?

+4
source share

Source: https://habr.com/ru/post/1622490/


All Articles