multiple configuration files

April 21, 2008

 
my application, a WCF service, uses Enterprise Application blocks, with a heavy dose of Validation blocks. Along with, Data, Exception and Logging blocks. there were 2 consumers of the application, a console host and a web host.

in a matter of time, the App.config and the web.config grew big, and was getting very difficult to maintain. (monstrous) to add to that, there were a lot of Ent Lib config settings duplicated between the .config files and synchronization was obviously an issue.  

this was primarily because, we were doing configuration based validation, and there were many fields to be validated across different validators. (50-70 fields with 3-4 validations each, do the math)

seeking isolation of the ent lib config settings for clarity and config re-use, i tumbled upon this good post by Tom. after skimming through the initial part, what i found the most suitable, was using a .NET Framework 2.0 feature, more than any Ent Lib configuration features.

 app.config/web.config

<?xml version=”1.0″ encoding=”utf-8″?>

<configuration>

  <configSections>

    <section name=”validation” type=”Microsoft.Practices.EnterpriseLibrary.Validation.

Configuration.ValidationSettings, Microsoft.Practices.

EnterpriseLibrary.Validation, Version=3.1.0.0,

 Culture=neutral, PublicKeyToken=null” />

    <section name=”loggingConfiguration” type=”Microsoft.Practices.EnterpriseLibrary.Logging.

Configuration.LoggingSettings, Microsoft.Practices.

EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral,

PublicKeyToken=null” />

  </configSections>

  <validation configSource=”validations.config” />

  <loggingConfiguration configSource=”logging.config” />

</configuration>

what this meant was i could pluck out the existing validation/logging/exception sections from my app.config and web.config files, put them in their respective config files and add the source files as part of my original WCF service, rather than the consumers.

e.g. a sample exception config file begins like this:

<?xml version=”1.0″ encoding=”utf-8″?>

  <exceptionHandling>

   …. <!– disaster recovery –>

  </exceptionHandling>

So the WCF service ended up with 4 config files, validations.config, logging.config, exceptions.config and data.config.

the build output dumped all the files into a common bin folder, and hence they found each other. i haven’t tried to link the external config files, if they are in a different directory.

<validation configSource=”??” />

probably it will work with a relative/absolute path too..

nevertheless, it was suitable for my requirements. now the console host, iis host and the soon to be added windows service host, all link to a single set of external config files.

the config management looks simple and clean now.

theres a solution to every problem; just that some are still being discovered..


relax! it’s just 0’s and 1’s

January 22, 2007

 

Welcome to my technical blog. some of the things i found interesting.. it is said about coding,

relax it’s just 0’s and 1’s

an object expert, if not a subject expert.

there are only 10 types of people… those who know binary and those who don’t…

code or code not.. dah! the musing says code!

life is an eternal beta..

and look what all things a 0 and 1 can do in this world….