views:

104

answers:

4

We have lot of configuration files used in our application. Atleast 100 different xml files for each customer containing at least 50-80 name/value pairs of configuration and all they are often change (atleast every month).

The configuration file looks something similar like below,

  <property id="url"  value="s123"/>
  <property id="input-element-name"  value="name" />
  <property id="input-element-xpath" value="//body;//form;//table[3];" />

Currently to read this values from xml file we use XmlReader et al and store it in a cache once the application starts (and this could be huge tomorrow when our customer base increases). To access the property ids we have created const variables in a static class to avoid typo etc.,

This approach was great when we had less configurations. Now, it is painful to maintain and add any new to this configuration file. Need to do rebuild etc., just kills the concept of keeping configurable values outside code.

I was just wondering if any recent developments in .NET space such as M language, IronPython could help here to have dynamically typed and compiled configuration values on demand when configuration file gets changed. We don't have any reservations in having xml format for configuration.

In summary, what I need is to have some .XXX files having our configuration values and if anything is changed or added that should be automatically compiled and can be used in our application without creating constants etc., I know something similar happens with .T files in VS.

I hope this could be doable ..

UPDATE

The idea of this question was not seems to be understood correctly or I wouldn't have spelled out correctly. Sorry for the trouble.

The custom configuration section may not appropriate for this problem, the reason is using ConfigurationSection requires code modification if I add any new name/value pair. However, this approach will work if only change values as name part is being mapped to property in the code.

I was wondering if i use any dynamic language breeds such as IronPython or M Language I could be able to move all XML to it and in my application I would able to see any changes to this file (using `FileSystemWatcher') and execute it to read the newly added configuration name/value pairs.

+1  A: 

I've used this typed configuration class from Rick Strahl - it worked very well for me.

RoadWarrior
+1. whut he sed.
Sky Sanders
I'd be a little nervous about that class, since it was first created before .HET had built-in typed configuration classes.
John Saunders
Yes, John, I would not use it, knowing how easy it is to build sections, but it can be a bit daunting for someone with limited configuration experience. I can see a use for rick's class. AFAIK it's not broken or anything, just a bit smelly.
Sky Sanders
@Sky: I didn't mean to suggest it was broken; only that it is not necessary in .NET 2.0. There's a standard way to do this now - custom classes are no longer necessary.
John Saunders
A: 

Please look at the classes in the System.Configuration namespace. They have been there since .NET 2.0, and give you strongly-typed access to XML configuration files, complete with validation.

John Saunders
+1  A: 

You can implement as many custom ConfigurationSections as you'd like.

This will allow you to model your configuration model as strongly typed objects.

Mark Seemann
+1 : The strong typed objects part is nice too, makes it a little more worth while over the normal configuration settings.
Ian
+1  A: 

Vadi, the purpose of external configuration is to obviate the need to recompile for configuration changes.

If the xml you present is representative of the type of information you need to use, a custom ConfigurationSection would serve you nicely and provide the type safety you want.

Sky Sanders