DCSIMG
Dynamic Application Configuration in .NET Applications - Leon

Leon

Dynamic Application Configuration in .NET Applications

We have couple of choices to work with application in .NET 2.0:

Pros Cons
appSettings section in standard configuration files Simple existing API, changes in web.config immediately reflected in application Cons: name-value string pares only can be stored, application need restart to accept external changes
Custom configuration sections Can store complex data Should be implemented for each configuration structure, implementation is not very intuitive, application need restart to accept external changes
applicationSettings section & Settings files Standard API, built-in (in VS2005) editor for simple types, support for design-time binding, writable from application code, complex types can be stored in ArrayList Limited supports for complex types, application need restart to accept external changes

Challenge

So what would I like to have?

  • I want to store and retrieve from configuration store arbitrary class.
  • If configuration changes between two subsequent attempts to configuration, later access should reflect changes.
  • I am too lazy to build implementation for each class, I'll have to store.

Solution

Solution based on using XML configuration file in any convenient schema. Configuration consists of classes that represent data, stored in configuration file and manager which is responsible to store, retrieve and cache configuration data. Manager uses simple XML serialization/deserialization to read/write data. Configuration file path stored in standard application configuration file. System.Web.Caching.Cache used to cache configuration data.

And what about implementation? To address my laziness problem, I built simple utility to generate the whole implementation from XML configuration file. All you need is supply configuration file path, output directory and desirable namespace. You can download result of this exersise here.

Read the whole article on codeproject.

שלח תגובה

(שדה חובה)  

(שדה חובה)  

(אופציונלי)

(שדה חובה) 

Please add 8 and 7 and type the answer here:


Enter the numbers above: