In order to use the configuration class effectively you should use a static instance of the class to avoid having to reload the configuration data from the store on every access. Since the class opens and reads the configuration store each time you create the instance, this overhead should be avoided. Static instances are a nice way to ensure the configuration data is only read once in the static constructor and provides easy global access to the configuration data from anywhere in your application.

We recommend you create an application level class that is used to hold static reference to any application global data, constants and objects. Your Configuration object should be one of the static properties. While you can also use any static object in the application framework, like Application object in ASP.NET we still recommend a separate object so the Application configuration and 'globals' object are portable with your business logic.

Here's a typical setup:

public class App { // static property on any class public static ApplicationConfiguration Configuration { get; set; } // static constructor ensures this code runs only once // the first time any static property is accessed static App() { /// Load the properties from the Config store Configuration = new ApplicationConfiguration(); } }

The App class has a static property ApplicationConfiguration that holds our custom configuration class. A static constructor is used to load the property with the configuration object. Static constructors are guaranteed to only fire once per application and are fired on the first access of a static propery. The first time you access the Configuration property the static constructor fires and the configuration object is loaded with settings from the configuration store. After that configuration data comes from the static/global instance only, unless you explicitly re-read the data from the store.

From then on you can access the configuration anywhere in your application via App.Configuration.Property. For example:

int maxListItems = App.Configuration.MaxPageItems; this.Page.Title += " - " + App.Configuration.ApplicationTitle;

The beauty of the static property is that it's accessible from anywhere and you never need to worry about instantiation of the configuration class outside of the static construtor. You simply reference the App.Configuration object and it will always be available!

The configuration class is globally available and accessible because it is static. When you need to update saved values back into the configuration store call the Write() method to persist the configuration:

App.Configuration.ApplicationTitle = "Something new is really needed"; App.Configuration.Write()

Note that writing requires the appropriate permissions (for example in a Web app the Web Server account needs write permissions for the web.config or other config file) and you can check bool result from the write method plus the ErrorMessage property for errors.