Created
August 9, 2010 19:16
-
-
Save jmarnold/515936 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BasicValidationRegistry : ValidationRegistry | |
{ | |
public BasicValidationRegistry() | |
{ | |
Scan(x => | |
{ | |
x.TheCallingAssembly(); | |
x.IncludeNamespaceContainingType<ModelMarker>(); | |
x.UseValidationAttributes(); | |
x.InheritValidationRules(); | |
x.ByDefault | |
.IfProperty(p => p.Name.ToLower().Contains("email")) | |
.IsEmail(); | |
x.ByDefault | |
.IfProperty(p => p.Name.ToLower().Contains("phone")) | |
.IsPhoneNumber(); | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CoreValidationRegistry : ValidationRegistry | |
{ | |
public CoreValidationRegistry() | |
{ | |
Scan(x => | |
{ | |
x.TheCallingAssembly(); | |
x.IncludeNamespaceContainingType<CoreValidationRegistry>(); | |
x.ExcludeType<CoreValidationRegistry>(); | |
x.LookForRegistries(); | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Validator.Initialize(x => | |
{ | |
x.AddRegistry<CoreValidationRegistry>(); | |
x.BuildDependenciesWith(ObjectFactory.GetInstance); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UserValidationRegistry : ValidationRegistry | |
{ | |
public UserValidationRegistry() | |
{ | |
// example of how you can mix and match validation approaches | |
For<UserInputModel>() | |
.Require(u => u.Password) | |
.Require(u => u.ConfirmPassword) | |
.Compare(u => u.Password, u => u.ConfirmPassword); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment