Programatically loading a Validation Configuration file

May 3, 2007 at 10:56 PM
I am having a scenario where I need to create a validator using validation rules stored in a config and I need to be able to specify the config file name when creating the Validator. How can I do that?

Right now I am storing the configuration rules in the app.config file and creating the validator as follows:

Validator<Customer> customerValidator = ValidationFactory.CreateValidator<Customer>("DefaultRuleSet");

But lets say I want to store validation rules in File A and File B, and at the time of creating the Validator, I want to specify the actual file name to use. How would I do that?

Thanks,
Rajesh
May 4, 2007 at 4:26 PM
The ValidationFactory Class you are using has several other CreateValidator Method Overloads that allow you to specify an IConfigurationSource from which to create the Validator.

     static Validator<T> CreateValidator<T>(IConfigurationSource configurationSource)
 
     static Validator<T> CreateValidator<T>(string ruleset, IConfigurationSource configurationSource)
 
     static Validator CreateValidator(Type targetType, string ruleset, IConfigurationSource configurationSource)

etc...

Regards,

Dave

____________________________

David Hayden
Microsoft MVP C#
May 9, 2007 at 6:32 AM
Thanks for responding. I am going to try out the overloads