Using the CMAB for Enterprise, Client, and User Settings
Applications use many forms of configuration data, storing settings that are used in applications, enterprise, client computers, and user settings. The Configuration Management Application Block (CMAB) is typically used for application settings, but it can be enhanced to support more complicated settings as well.
Virtually all applications require some form of configuration data. Enterprise configuration data includes settings that are global to the organization, including items such as the organization's name, address, and logo. Perhaps more importantly, enterprise configuration may include information such as the address of the enterprise LDAP server or authentication service.
The simplest way to use the CMAB to store enterprise settings is to use a centrally-located XML configuration file.
Client configuration data includes settings that are global to all applications on a client computer. Often, this includes a flag indicating whether the client is a production, test, or development computer. Sometimes the configuration data includes paths to log file locations or other system-level policy settings. Configuration data may also include overrides for enterprise configuration that forces applications to use a test server instead of a production server, for instance.
Application configuration data includes settings that are global to all users for a specific application. Often, application configuration includes settings to configure remote server addresses, local caching, or connection strings. These settings may include overrides for enterprise or client computer configuration settings to provide application-specific requirements.
User configuration data includes settings for specific users of a specific application. This type of data must be stored in a per-user location and preferably supports the concept of roaming user profiles. The primary options for storing user configuration data are isolated storage, the user's Application Data directory, or the registry.
Although the .NET Framework itself provides no direct support for managing client computer or user configuration data, with minor enhancements, the CMAB can be used to manage this data as well.
The CMAB is often used to read and write configuration data from the application's configuration file. It can also be used to read and write configuration data from other arbitrary XML files as well as the Windows registry or a SQL Server database.
By using the ability to read and write to arbitrary XML files or a SQL Server database, you can use the CMAB to access enterprise configuration data. All that is required is either a central enterprise XML file on a network share or a centrally available SQL Server database that can be used by any application. If either of these conditions can be met, you can use the CMAB for this purpose.
If these conditions can't be met but the data is in some other centrally available location, you could write a custom storage provider to allow access to those settings. An example might be a centrally available LDAP server that contains all enterprise configuration data. You could write an LDAP storage provider that plugs into the CMAB to read from this data store. Writing such a provider is outside the scope of this article.
The simplest way to use the CMAB to store enterprise settings is to use a centrally-located XML configuration file. This is exactly the same as storing any other XML configuration data using the CMAB with the exception that the CMAB is configured to reference the XML in a specific file on a shared network drive.
In the case of Listing 1, the path attribute is used to indicate that the settings are stored in a specific file other than the application configuration file. As long as the H: drive is available enterprise-wide, you can use this technique for enterprise settings.
By: Rockford Lhotka
Rockford Lhotka is the author of several books, including the Expert VB and C# 2005 Business Objects books and related CSLA .NET framework. He is a Microsoft Regional Director, MVP, and INETA speaker. Rockford is the Principal Technology Evangelist for Magenic (www.magenic.com), a Microsoft Gold Certified Partner.
Although the .NET Framework itself provides no direct support for managing client or user configuration data, with minor enhancements, the CMAB can be used.