Main Contents

FluentValidation Xval Integration

Schotime @ June 13, 2009

.NET

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


book mark FluentValidation Xval Integration in del.icio.us submit FluentValidation Xval Integration to digg.com


4 Comments

  1. hotspot shield lauch August 4, 2009 @ 10:12 am

    Very enjoyed this! Well done!

  2. CitizenBane August 18, 2009 @ 1:15 pm

    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 January 20, 2010 @ 2:19 pm

    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?)

  4. Schotime January 22, 2010 @ 11:02 pm

    It has been integrated into the trunk of FV.
    The integration is part of the v1.2 in its own project and the source is available from http://github.com/JeremySkinner/FluentValidation

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Feed
24,353 spam comments
blocked by
Akismet