Search code examples
fubumvc

Validation in FubuMvc 1.0


I'm new using FubuMvc, I recently Update to version 1.0 which doesn't have any documentation and it seems like there's a lot of breaking changes in the code, I'm trying to understand how the validation rules and validation in general works in fubu.

I can't find the validation method even If I import FubuMVC.Validation

this.Validation(x => { 
    x....
}); 

is there any new approach for this, I just would like to have clear the concept of how the validation occurs in fubu.

Can I apply a convention for validation? Example: to all my Entities that contain a field named "email" apply a regex validation with a standard formatting.


Solution

  • The new FubuMVC.Validation bottle is completely drop-in and doesn't require much configuration at all. If you want to configure the chains it applies to, simply do:

    AlterSettings(x => ...); <--- in your FubuRegistry

    Right now, we don't do conventional validation that way out-of-the-box. You have two ways:

    1. Attributes
    2. The OverridesFor DSL in FubuMVC.

    Examples of both of those can be found here (respectively):

    1. https://github.com/DarthFubuMVC/fubuvalidation/blob/master/src/FubuMVC.Validation.StoryTeller/User.cs
    2. https://github.com/DarthFubuMVC/fubuvalidation/blob/master/src/FubuMVC.Validation.StoryTeller/AccessorOverridesModel.cs

    That being said...

    Anything that implements IFieldValidationSource gets automatically registered into your container. This is how we convert from OverridesFor to rules, for example:

    https://github.com/DarthFubuMVC/fubuvalidation/blob/master/src/FubuMVC.Validation/AccessorRulesFieldSource.cs

    So you could reflect on that property and return an EmailFieldRule. Something like this:

    https://gist.github.com/4540861

    Hope this helps,

    Josh