FluentValidation Xval Integration

After a few months of using FluentValidation I asked its author Jeremy Skinner if it were possible to integrate this with xVal. At that time it was not possible because there were no easy way to access the properties needed by xVal. After submitting a few patches, we now have a solution which enables xVal integration with most of the FV validators.

It currently supports the following FV validatiors:

  • NullValidator
  • NotEmptyValidator
  • LengthValidator
  • RegularExpressionValidator
  • ComparisonValidator including:
    • Equal
    • Not Equal
    • Greater Than or Equal
    • Less Than or Equal

To configure the integration we need to tell xVal to use the FV rules provider rather than the default one. This is done in the global.asax.cs in Application_Start().


xVal.
ActiveRuleProviders.Providers.Clear(); xVal.ActiveRuleProviders.Providers.Add( new FluentValidation.xValIntegration. FluentValidationRulesProvider(new AttributedValidatorFactory()));

The rules provider here is instructed to use the AttributedValidatorFactory to instruct the provider to use the attribute attached to the model class to find the validation class for that model.

Note: This is still new and xVal is still in beta so there may be some issues. If you find any please let me know so we can fix them as soon as possible.

Hopefully once its ready it can be checked in with the other providers at the xVal codeplex site.

This is currently in the development source code which can be downloaded and tried now.

Cheers,

Adam

Advertisements
This entry was posted in .NET and tagged , , , , . Bookmark the permalink.

4 Responses to FluentValidation Xval Integration

  1. Very enjoyed this! Well done!

  2. CitizenBane says:

    Uuugg! I should have read your blog post over again on the limitations, because I kept trying to validate an EmailAddress (client-side), through xval, but it would not work!

    Frustration (due to my part) aside, I’m very thankful for your xval integration. This will definitely save me a lot of time!!

  3. Patrice says:

    Where can I download your FluentValidation.xValIntegration. FluentValidationRulesProvider ?

    I got a compile error with the Fluent Validation version 1.1
    The type or namespace name ‘xValIntegration’ does not exist in the namespace ‘FluentValidation’ (are you missing an assembly reference?)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s