This project is read-only.

Configure Validation Catalog

Discovering Specifications

Why should I register my specifications?
Specifications for types are resolved by the ValidationCatalog based on the type of the object. This eliminates the requirement for the Developer to specify which Specification to use to validate an object. In the example below, when validating an object with the catalog, explicitly naming the Specification to use to validate a Contact class isn't required, because it was registered with the ValidationCatalog.

var contact = new Contact {FirstName = "Joe", LastName = string.empty};
var validationResults = ValidationCatalog.Validate(contact);


You can scan an Assembly or Assemblies for Specifications. Below are the methods provided to tell the ValidationCatalog where to look.

All Assemblies in AppDomain

 ValidationCatalog.Scan(x => x.AddAssemblies(AppDomain.CurrentDomain.GetAssemblies().ToList()));

Specific Assembly

Assembly assembly = Assembly.LoadFrom("SpecExpress.Test.Domain.dll");
ValidationCatalog.Scan(x => x.AddAssembly(assembly));

From Path

ValidationCatalog.Scan(x => x.AddAssembliesFromPath(@"c:\MyApp"));

Current Assembly

ValidationCatalog.Scan(x => x.TheCallingAssembly());

Configuring Message Stores

Creating new Message Stores is covered here.

Adding Custom MessageStores

ValidationCatalog.Configure( x => x.AddMessageStore(new ResourceMessageStore(TestRuleErrorMessages.ResourceManager), "MyMessageStore"));

Changing the Default MessageStore

ValidationCatalog.Configure(x => x.DefaultMessageStore = new SimpleMessageStore());

Last edited Feb 23, 2010 at 5:43 PM by TechnoAg, version 4


No comments yet.