Click here to Skip to main content
11,574,494 members (59,530 online)
Click here to Skip to main content

Enterprise configuration management

, 23 Nov 2009 CPOL 22K 42
Rate this:
Please Sign up or sign in to vote.
Configuration of .net applications using database


This article details out configuration management in an enterprise application setup with common configuration store.

Any large enterprise application has many moving blocks. They all need to be configured for a proper working of the application. As the application size increases or for scalability the same configuration has to be repeated in different applications. For most applications once the configuration has been changed the application needs to be restarted.

This article is more of a discussion in which I will try to have a conversation into my thought process.

It should be noted the intent of this article is not to provide solution to enterprise configuration, instead it is to let the reader know of the challenges one may face and a set of possible solutions, the designer of the application will then have a choice.


This article explores a technique in which we will develop a mechanism for configuration management in which-

1. There is centralised location for keeping common configuration elements.

2. Mechanism for keeping instance specific configuration.

3. A mechanism (and if possible a framework) for instantiating classes such as web service, WCF client or servers and others which are configured using app.config / web.config

4. A mechanism for caching the configuration which is stored in the common configuration store.

5. A common code base to read configuration

6. How to deploy this common codebase.

Let's try to come up with options / ideas for each of our design goal, see what else we need to read up and to achieve these design goals.

Doing this is a lot of effort so work on this technique if and only if you have a large application with many moving parts. If you believe that in future your application will in future grow into something large then read the section on planning for scalability today in this article.

If the next section is very confusing don't worry we will get into much more details.

Why do this

This article has been written for applications which have multiple instances installed in the eco system. It is helpful if and only if you need load balancing and repeating configuration across multiple sites. If you use this application you will not have to update multiple locations with configuration.

If you have a simple web application or service with few components this technique is not for you.

The Ideas

The challenges and ideas for the stuff we are about to face - This section details out the ideas of how to solve the requirements stated above, we are not yet going into solution mode all we are doing is gathering all the challenges we are going to face.

1. Centralised location for common configuration elements- This is rather trivial, we should create a separate database in which we will keep these configuration elements. Once out of the idea stage we will detail out a generic schema for this task.

2. Mechanism for keeping instance specific configuration - This is rather debatable, we can think of two ways to do this, one we could modify the central database with some additional fields to identify if the configuration is global or for a central server, the other is keeping instance specific information in regular app.config / web.config files. If we do keep them in .config files then for a large installation we need to come up with an installation utility. My preference is to use the central database for this task.

3. Mechanism to load configuration - There will be two kinds of configuration items you will face one which is defined by your business logic such as SMTP server name required by your .net component or may be the maximum grid size. These will be simple as rather than reading a key value pair or reading from a custom configuration section you will have to read from the database, the next are components which are provided by .net such as web service proxy class or WCF configuration. These will be more challenging we require a central location to get instances of these classes which create an instance will configure these elements before returning an instance. For example if we want an instance of web service proxy we need to set the url of the web server and these have to be done at a custom location.

To do these we need to provide a set of wrapper factories and only use them to create instances of the objects, an example of this factory method could be

WebServiceProxyClass GetInstanceOfWebServiceProxyClass(string webServiceId)


Create an instance of the proxy

Get values from database for the url, Soap format etc...

Set values for some optional parameters such as time outs...

return the instance


This wrapper factory is essentially is a factory.

4. Mechanism for Caching configuration -To have maximum throughput the configuration needs to be cached by the client of the configuration not by the configuration provider. This means if our application required a windows service and a web site both these applications will have to cache this configuration and provide a common API to access this configuration elements. This caching will provide better performance, however it not an explicit requirement. Once caching is in place things like cache expiry and related polices will come into play. In this article we will use the Microsoft enterprise library for the required caching support. The details of this block may be obtained from

5. Common codebase to read configuration - Once you have actually planned using this centralised configuration management, it is required that the configuration be read from a common class so that is the mechanism of reading the configuration changes we don't go for a toss. This idea is to have a codebase in which we use code like ConfigManager.GetConfig["KeyName"] or ConfigManager.MyTestKey.

6. How do we deploy this common code base - This final question may sound irrelevant however it is of great importance, we are making a policy decision here. There are two ways to deploy the common code base we may deploy one include it as an in-process dll this is fine as long as only one application with multiple components is going to use the configuration, on the other hand what if you want to make this configuration management an enterprise applications (please note the plural) configuration tool. What if multiple applications will get there configuration from this application, for many enterprise applications for consistency configuration data like SMTP server or number of rows in a grid may be stored at a central location. In such a scenario we will need to graduate our little utility into an Enterprise configuration service. We need to ask ourselves is this an overkill or will we face this in future, what if we want to keep this deployment option open today and for now just do the bare minimum? Well WCF comes to rescue. This article on WCF null proxy allows in process execution of a WCF request thus allowing quick work today but extendibility in future.

So let's sum up what all do we need to learn here to go ahead with this article -

1. How .Net applications are configured

2. The design pattern of Factory and wrapper (we only learn about wrapper for the intent even though the code here will be essentially a factory)

3. Enterprise library caching block, you may choose to read about another caching provider or write your own

4. WCF and WCF deployment options

Planning for Scalability today -There is a possibility that the business case you have today doesn't justify such a big bang approach but you to protect yourself against changes in future. To do that you only need to do one thing today vis build a common class through which you will access all your configuration. This means there will be no line of code like ConfigurationManager.ApplicationConfiguration["SampleKey"] in your business classes, there should be in some custom configuration classes. You will however not be shielded against the default configuration providers for WCF or Web services and others.

The Logical architecture

With all this in mind lets jump into the logical architecture of this application. We will try to design it with purity in mind and keep any use case specific task to a minimum. We will define the various components and try to map them to six criteria we have set above.

Application A / B - This is any .net executing assembly in a given process space. It could be a windows service, a web site or any independently executing component.

The application has many components which require the use of the configuration. The application has a configuration cache the job of this component is to cache the configuration items for the application. This will result in better performance. This cache will call the config api to obtain the values for configuration, it will provide necessary logic to add site specific information.

The application also has a wrapper factory. This a common component which creates instances of objects which require the use of configuration cache. Some examples are creation of database connections, WCF or web service proxy class, WCF hosting etc. The idea is that we will use this class to get the required instance

For example SqlConnection sqlConnection = WrapperFactory.GetConnection(Id);


Configuration Access API - This is a standalone component which will provide us with the configuration values. This will be the data store that the configuration cache will access. This is the location which is now replacing the ConfigurationManager class of .net and the only reason we have put in the cache is to ensure that we have a high performance application.

Configuration DB - This is the actual data store for all the configuration and is replacing web.config or the app.config. It will contain the schema for storing both global and site specific information.

The Design

Usually when I am trying to design something, I have two approaches in mind, one I come up with the E-R model or the database model and build on that. On other occasions I try to come up with the object model / domain model and work from there. In this scenario I will come up with the object / domain model the reason for this is that the nature of this application is service driven and not storage of data.

The most important interface and by virtue of which other things that will be driven in this application will be the configuration access API. The database schema will easily flow from it. The cache will always be a no brainer as it will be a wrapper on this API to ensure fast access, while the wrapper factory quite challenging is not the heart of this application. The wrapper factory exists only to provide instance of some classes which otherwise would have been.

The Configuration API interface - What do we expect from this configuration API?

We expect that we will pass it a site name and application name and it will return us

1. All global configuration across sites and applications

2. All global configuration across applications

3. All local configuration for the Site

4. All global configuration for the application

Finally as a consumer of this information I am not in the fact that some configuration is global while other stuff is for me, all I want to know is the entire configuration which affects me.

What will be this configuration information

1. Simple key value pairs

2. Key value pairs which are ideally stored as a part of a custom configuration section but have been decomposed. We of course need a mechanism to group them together and yet keep things generic.

So essentially entire configuration can be considered as a key - value pairs which need to be grouped logically. A logical group is a bunch of key value pairs which are arbitrarily grouped from the API point of view. The user of this information however needs this grouping to properly instantiate the consumers of this configuration.

With this in mind let's try to define the Entity object (or the value object or the data transfer object or the DTO whatever you may call it) to capture this information along with the methods on the interface to access a DTO.

To achieve this lets describe a bunch of definitions which will be used in our object model.

· Site - A site is an instance of an application executing on a machine in a separate application domain.

· Application - An application is an executing assembly hosted in a process space.

· Machine - A machine is a physical object on which one or more applications are executing.

Overriding criteria

In the system machine, application and site level configurations can be defined for any executing assembly, in case of a collision machine level configuration is override by application level and application level is overridden by site level configuration. Conceder the example

Machine configuration











Application configuration











Site configuration













The keys available at the application are


Override order



M1 <A1 <S1 => Site overrides both machine and application



M2 <A2 => Application overrides machine



M3 < S2 => Site overrides machine






A2<S3 => Site overrides application











The design should support a custom override criteria so that future changes are simple.

Server Side Object Model


Class Details

1. ConfigurationElement - This class contains essentially a bunch of key value pairs which form the values for various attributes of configuration. The entity also contains the PropertyName property which may be used to identify the property being set. A client may use reflection/introspection or indexers (where possible) to use this. The property OverrideType may be used to define what has given this field its value.

2. ConfigurationGroupData - This class is used to logically represent a group of keys associated with one of the components for a site. Examples can be a given WCF component, a webservice, a Database connection string, some keys in appSettings and others.

3. ConfigurationEntity - This class contains all the configurations for a site. The site is identified by a site ID. This site id is a unique combination of application and machine.

These class details / object model form the essential data contract for our application.

The next section contains the interface to obtain configuration from the data store.


Based on the description of a site vis machine + application name we return the configuration information. The data is overridden based on the override criteria. If a machine is not specified or not found then configuration for the given application should be sent back.

So in principle we get all the key's for site which can be machine level, application level or site level keys and check which overrides what, create a ConfgurationEntity and send it back.

The IConfigurationStore in principle forms the operation contract of our work.

Database Design

This section details out the database schema for the application. We will not dive deep into every column and its purpose, I am sure the audience are aware of IsDeleted flags for soft deletes or the purpose of CreationDateTime and LastUpdateDateTime

1. Deployments - This table contains the names of various units of deployments such as definition of applications, machines or a combination of machine and application vis sites.

Some examples

Machine Name

Application Name



This configuration is sent back whenever Server1 is requested in context of any application.


This configuration is sent back whenever Application1 is requested in context of any application.



This is sent back when ever Application1 is requested by Server2. The keys of this site override the ones in Application1.

2. Components - Components are any separate logically grouped bunch of keys in an executing application. Some example are WCF related keys, Web service related keys, DB related keys and others. We define a loose definition of component type this may be WCF while component name is an instance of component type for example a WCF server keys for the identity service of DB connection keys for the reporting server. The component type tells what is the exact area of configuration while the instance is the specific deployment. It is similar to class vs. instance of class


1. Keys - This is the actual bunch of keys associated with a component. For example with WCF instance it may contain the url, time out and others. With each key we also store a property

2. KeyValues - These are the actual values for a given key. They can be overridden on Application and Site level.

3. ComponentDeployment - This is a logical grouping of components for a deployment. For example a web application contains a bunch of WCF deployments, one database deployment and some details of http runtime details.

The schema given above is rather generic, in case however for operational efficiency you may create table structures which is structured for various entities.

Override Algorithm

As a part of design we also give here the overriding algorithm as under. This is just one of the possible implementations of the delegate the consumers of this framework may choose to implement their own.

public bool IsOverrideImplementation (OverrideType oldValue, OverrideType newValue)


//Return true if new value can override old value.

return newValue > oldValue;


This concludes the server side of things, let us debate a bit on the client side of things which include the caching of the keys and a bunch of factories which are required to instantiate a class.


The ConfigurationEntity must be cached in the client application. We need a mechanism for cache refresh. It is highly recommended that before we go ahead we should read the article

The reason we propose this as a caching tool instead of .net cache is because it allows caching in any kind of .net application and not just web application. Further this tool allows expiration scavenging and other features.


On the client end a whole bunch of factories have to be created. These will be used to instantiate the elements. Why do we need these?

Conceder the example when we wish to use a a web service we create an instance of the proxy

Service = new Service();

internally this constructor will do a couple of things

1. Assign the URL to access the web service.

2. Assign the format of requests such as Soap or Http Post

3. Set the time outs and many other properties.

The job of this factory will be to create an instance and assign these values from the cache.

If the application has too many class types and classes which get effected by this configuration, we may use an abstract factory pattern instead of factory pattern.

Contents of the .config file on the client

We should understand and acknowledge that not everything can be moved to the DB structure. We will have to maintain at least a WCF end point to access the configuration store for an out of process configuration store. Things like details of httpModules, debug/release mode and others settings which need to be loaded early on need to be kept in the .config file.

A sequence diagram is called for

Let's try to understand the overall flow how a certain application will be configured in the under given sequence diagram.

There is not much to say here. Any class which needs to be instantiated requests the wrapper factory to create the instance. The wrapper factory has all the logic to create instance except for config values. These values are obtained from the cache. The cache fills its values from the the WCF API. We fill the entire cache in one go.


At this point of time I intend to stop, as this article is getting too long. At some time in future I will share the sample implementation.

Finally If you find this article helpful please rate it....


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Architect Imfinity
India India
Hi I have been working on enterprise applications for last six years.

You may also be interested in...

Comments and Discussions

QuestionExceptionShielding with AsyncPattern=true in wcf Pin
sumit123567818-Feb-13 23:21
membersumit123567818-Feb-13 23:21 
AnswerRe: ExceptionShielding with AsyncPattern=true in wcf Pin
gaurav_verma_mca19-Feb-13 10:01
membergaurav_verma_mca19-Feb-13 10:01 
Generalsample code Pin
somegiri7-Dec-10 3:06
membersomegiri7-Dec-10 3:06 
Generallittle typo error Pin
roberto galbiati23-Nov-09 3:08
memberroberto galbiati23-Nov-09 3:08 
GeneralRe: little typo error Pin
gaurav_verma_mca23-Nov-09 3:12
membergaurav_verma_mca23-Nov-09 3:12 
GeneralThanks. Pin
thompsons19-Nov-09 8:57
memberthompsons19-Nov-09 8:57 
GeneralRe: Thanks. Pin
gaurav_verma_mca19-Nov-09 21:46
membergaurav_verma_mca19-Nov-09 21:46 
QuestionIs there sample code? Pin
lcqishi18-Nov-09 19:26
memberlcqishi18-Nov-09 19:26 
AnswerRe: Is there sample code? Pin
gaurav_verma_mca18-Nov-09 19:44
membergaurav_verma_mca18-Nov-09 19:44 
It will be done in part 2.
GeneralRe: Is there sample code? Pin
lcqishi19-Nov-09 16:26
memberlcqishi19-Nov-09 16:26 
GeneralRe: Is there sample code? Pin
Éric De Carufel1-Feb-13 0:35
memberÉric De Carufel1-Feb-13 0:35 
GeneralRe: Is there sample code? Pin
gaurav_verma_mca1-Feb-13 5:16
membergaurav_verma_mca1-Feb-13 5:16 
GeneralRe: Is there sample code? Pin
AndrzejLipski15-May-14 11:09
memberAndrzejLipski15-May-14 11:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150624.2 | Last Updated 23 Nov 2009
Article Copyright 2009 by gaurav_verma_mca
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid