Friday, 25 April 2008

.NET Settings, Settings and more Settings (the configSource and File Attribute)

well, today for the first time I thought I would tackle the problem we have in managing the settings of our .NET applications. It's friday so I thought I'd celebrate with this.
Anyway, so we have loads and loads of settings for our applications some are:
  • specific to the application
  • specific to the configuration/environment
  • generic to all of the applications

Most of our applications are ASP.NET 2.0 web apps, and therefore we had previously stored our settings data inside web.config under the node.

Then last year we need to split out the settings on a per-configuration / environment basis, so we created a /_config/ directory in the root of our web app.

In this we placed

  • /dev,
  • /prod and
  • /staging.

The principle is simple: just create appSettings.config and place it inside /dev, then reference it from web.config with the "file" attribute of the appSettings node; e.g. web.config ->

The file attribute will mean the contents of the specified file will override and merge with nodes directly underneith the inline node. This is cool. Because you can specify environment-agnostic settings inside the inline section of web.config, and then they will either be overriden by nodes with the same name inside the dev\appSettings.config file.

Great... kinda.

But the problem is, we actually don't want to maintain settings that are shared amongst different applications inside web.config. This is because if one setting needs to change, you need to specify the change throughout all web.configs of all applications.

We can't "share" the web.config amongst all applications, as each app needs different web.config sections / settings for other stuff. Also, we can't share a section of web.config.

So how can we find a neat solution to just:

  • Store and share settings that are agnostic to the application, the environment in which the application is deployed and are essentially global to a company's apps.
  • And also, specify settings that are the opposite: i.e. settings that are specific to the app and the environment.

I had tried using a heirarchy of file attributed nodes, i.e. in web.config specify a file containing the agnostic app settings and the specify a file inside that for app/env-specific settings... but .NET doesn't support merging down more than 1 level.

The Use Of The File Attribute and Config Source Attribute
arrrrh! that's the one.

So the solution is to put inside web.config:

[no inline nodes allowed]

Inside GenericAppSettings.config put:

Then create dev\appSettings.config



In our source control management system (VSS), we then share GenericAppSettings.config, amonst all of our apps and now we can rest assured that nothing will be left as obselete or broken. i.e. Generic settings can now be updated once for the whole enterprise.

so there you go another great solution for configuration management!

Kris

Thursday, 24 April 2008

Wednesday, 23 April 2008

Me


Drinking again