How to use the ruleset functionality of FluentValidation in Web API?

8

I would like to use a FluentValidation feature called ruleset in a Web API project because it does not I want to have to be doing model validation manually every time an action method is called.

So I used the FluentValidationModelValidatorProvider.Configure to add the FluentValidation at ModelValidatorProviders so that my models could be automatically validated before being sent to a action method .

So far so good, but for me to continue configuring FluentValidation in my project, for it to do the validations automatically, I just need to use the CustomizeValidatorAttribute on the desired models as follows:

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

The problem is that this attribute is only available for the more specific FluentValidation package that is intended for ASP.NET MVC. What could I do to have this functionality in the Web API?

    
asked by anonymous 06.01.2016 / 12:31

1 answer

3

According to this issue in the project's own GitHub, there is no way to do this and the author has no intention to do, not in the near future.

Follows the author's English text:

  

No plans to make a WebApi version of CustomizeValidator (unless someone wants to submit a pull request), sorry.

     

There are no changes to the mvc / webapi integration now - all future development efforts in this area will be focused on integration with ASP.NET 6 with the new mvc / webapi.

     

- JeremySkinner

Also remember that this was on June 12, 2015, and I did not find out if someone else implemented something and did not send the pull.

    
07.01.2016 / 14:35