Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to handle multiple config file instances?

We run a complex system written in C#.NET 3.5, consisting of 20+ websites, 10+ windows services and various scheduled tasks and helper apps.

Each of these is bundled with one or more of our framework and business logic DLL's. These DLL's have extensive config settings, and this has turned into a nightmare where we're maintaining over 40 config files for multiple instances of the same class libraries.

We don't register our DLL's in the GAC for various reasons: 1) We like the flexibility of quickly rolling out changes to selective projects without rebuilding the whole system or causing unnecessary downtime. 2) Some instances of the DLL's require slightly different configs; for example some projects use different connection strings, notification e-mail addresses and so on.

We experimented with the AppSettings file/configSource attributes in Web.config/App.config, but those only work with relative paths, not across projects. We considered saving the defaults in machine.config but this is a mission, being too cluttered and full of important stuff unrelated to our projects.

Our current "solution" is to use our own config file format, which first checks for a config in the current project's "bin" folder, and if that doesn't exist it loads from a hard-coded central location. This allows us to override settings when necessary but use the default settings the rest of the time.

Ultimately what we want is to have each class library default settings in a central location, and then each instance could have an optional config file which only overrides those settings that differ from the default.

Is there a suggested, industry-standard way of solving this problem in .NET ?

like image 219
realworldcoder Avatar asked Jan 08 '10 01:01

realworldcoder


People also ask

Can you have multiple config files?

Yes you can have two web. config files in application. There are situations where your application is divided in to modules and for every module you need separate configuration. For example if you have a application which has two modules lets say accounts and sales.

How do you make a good config file?

A good configuration file should meet at least these 3 criteria: Easy to read and edit: It should be text-based and structured in such a way that is easy to understand. Even non-developers should be able to read. Allow comments: Configuration file is not something that will be only read by developers.


1 Answers

If this is all within the same company why don't you just store the configs in the database? I believe the Enterprise Framework even has adapters you can plug in to do just this.

I know at our company since we had sites running in webfarms we would store the config in the db, then if we needed to change something we would have a db script update the config. no need to push to the sites, just had to restart the site or touch the web.config to force the reload.

Another solution we had for other items were to use a database that housed key value pairs along with other types of config data so that we could also easily change things across our website / windows forms projects that used the same components.

So I guess what I'm saying is if they are all within the same company / sphere of influence such that you could use a database that is central to them all just use the DB.

Don't polute the registry.

like image 185
Joshua Cauble Avatar answered Nov 03 '22 03:11

Joshua Cauble