VAB Multiple Config Files

Topics: Validation Application Block
Apr 13, 2010 at 6:57 PM

I am working on the SaaS apps and have a following scenario where i have to use mutiple configration files that contains validation rules.

Have main web application AppA that has a web.config. AppA used the class library ClassLibX, ClassLibY and ClassLinZ.

Each class library has their own App.config that contains a validation rules that applies to classes in that library. (ClassLibX.Config, ClassLinY.Config, ClassLibZ.config)

How can i include all this 3 config file to mail web.config and validate my class library object?

I tried to use <enterpriseLibrary.ConfigurationSource selectedSource="File Configuration Source">

but that allows to specify only one config file.

Any help appriciated.





Apr 13, 2010 at 11:52 PM

Yes, you can only point to one config file in the configurationSource section.  You should modify your code in each class library to use its own config file.  Use the overload of ValidationFactory which accepts an instance of IConfigurationSource.  You can refer here for the example -


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Apr 14, 2010 at 11:10 AM

It is possible to do this. Please see this discussion here on the entlib codeplex site.

Apr 14, 2010 at 11:50 AM

I should definitely keep this in mind.  Thanks dot_net_junkie.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.


Apr 14, 2010 at 4:15 PM
Edited Apr 14, 2010 at 7:48 PM

Thanks dot_net_unkie and Sarah. The link is quite useful.

Is there a way I can load the config file at the time of validation?

e.g.  I can specify as bellow or may be constrct some object befor call to validate?


results = Validation.Validate(customer,"app.config");




Apr 14, 2010 at 6:35 PM

One more question.

Is this something implimented in EL 5.0?


Apr 14, 2010 at 7:34 PM
Edited Apr 14, 2010 at 7:35 PM

Hi Timirp,

It is possible to load the configuration just before validating as follows:

IConfigurationSource source = new FileConfigurationSource("validation.config");
var validator = ValidationFactory.CreateValidator(customer.GetType(), string.Empty, source);
var result = validator.Validate(customer);

However, please note that this does not load the configuration each time before validating. Although you might create a new FileConfigurationSource every time, the actual configuration that is used by the FileConfigurationSource is cached during the lifetime of the app domain. So when you want to change a configuration file, without a app domain restart, you're out of luck.

>> Is this something implemented in EL 5.0?

EL 5.0 will not have mechanism like ValidationConfigurationSourceCombiner. It would be great if a future version would contain such a feature though.