VAB Multiple Config Files

Topics: Validation Application Block
Apr 13, 2010 at 7: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 14, 2010 at 12:52 AM

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 - http://blogs.msdn.com/tomholl/archive/2006/04/02/entlib2externalconfig.aspx

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Apr 14, 2010 at 12:10 PM

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

Apr 14, 2010 at 12:50 PM

I should definitely keep this in mind.  Thanks dot_net_junkie.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

 

Apr 14, 2010 at 5:15 PM
Edited Apr 14, 2010 at 8: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?

ValidationResults

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

 

 

 

Apr 14, 2010 at 7:35 PM

One more question.

Is this something implimented in EL 5.0?

 

Apr 14, 2010 at 8:34 PM
Edited Apr 14, 2010 at 8: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.