How to use Fluentvalidation ruleset functionality in Web API?

Asked

Viewed 157 times

8

I would like to use a feature of Fluentvalidation calling for ruleset in a web API project, because I don’t want to have to be doing model validation manually every time a action method is called.

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

Up to this point everything is fine, but for me to continue the configuration of Fluentvalidation in my project, for it to do the validations automatically, I just need to use the attribute CustomizeValidatorAttribute models that are desired 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 I could do to have this functionality in the Web API?

  • 3

    According to that Issue there is no forecast for this integration.

  • 2

    +1 For introducing me FluentValidation :)

  • There’s no answer, you can’t do it.

1 answer

3


According to that 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.

Follow the text, in English, of the author:

No plans to make a Webapi version of Customizevalidator (unless someone wants to Submit a pull request), Sorry.

There are unlikely to be any more 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 Combined mvc/webapi.

--Jeremyskinner

Recalling also that this was on 12 June 2015, and I found no information if anyone else implemented something and did not send the pull.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.