Dynamicaly Loading Rulesets at Runtime

Topics: Validation Application Block
May 3, 2007 at 9:32 PM
I am using the VAB and would like to be able to create plugins with custom rulesets. My thoughts where that I would allow a plugin author the ability to provide any number on side-by-side rulesets (as config files) that would be loaded when the plugin was loaded. How do you read configuration files at runtime?

Also, is it possible to use a FileSystemWatcher to watch for configuration file updates (or new configuration) and reload them as needed?
May 4, 2007 at 4:46 PM
The ValidationFactory Class has several CreateValidator Method Overloads that allow one 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)

You could use a FileConfigurationSource to specify a file at runtime.

I haven't personally tried to use a FileSystemWatcher Class to reload validation information at runtime upon changes.




David Hayden
Microsoft MVP C#
May 16, 2007 at 3:07 PM

Sorry for the long wait between posts but I've been dealing with graduations.

One quick question, once I use the above to do the validation, how do I make the loaded configuration available for WinForms Validation Integration?
It seems that when ValidateChildren() is called the underlying infrastructure can't find the ruleset (because I am dynamically loading it?)