Browse DevX
Sign up for e-mail newsletters from DevX


Configure It Out with the Configuration Management Application Block : Page 6

Nearly every application needs some way to configure itself so that it can interact with a given environment. For the simplest applications, app.config or machine.config probably meet your needs. For more complex applications you probably need something a bit more robust, secure, and scalable—and that's when you need to explore the Configuration Management Application Block.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Getting Underneath the Hood
The extensible design of the CMAB allows the creation of new components that plug right in. This extensibility is provided by interfaces. In order to create a new component for the CMAB, inherit from the specific interface for the component being targeted and implement it. The CSH Interface
The CSH uses the IConfigurationSectionHandler interface in the .NET System.Configuration namespace for reading data and provides a new interface, IConfigurationSectionHandlerWriter, for writing data. The IConfigurationSectionHandler is used to simplify the implementation for storing read-only configuration data in the application or machine configuration files. Providing this ability allows you to use the exact same implementation whether you want to use the standard .NET configuration files or an external data source to store configuration data.

The IConfigurationSectionHandler uses the Create method to deserialize an XML node into an object. It's up to you to provide the implementation to deserialize the data in much the same way you would when using the IConfigurationSectionHandler.Create method with the .NET configuration files. The IConfigurationSectionHandlerWriter inherits from IConfigurationSectionHandler and provides a new method that needs to be implemented, called Serialize. This is where you will implement the serialization of your object into an XML node.

Configuration Section Provider Interface
The CSP interfaces provide the means to actually read and write configuration data to and from the data storage provider whether it's a database, an XML file, or something else. The CSP interfaces consist of the IConfigurationStorageReader interface for read-only operations and the IConfigurationStorageWriter interface for read-and-write operations. It is assumed that if you are going to write data that you are also going to read it as well. The IConfigurationStorageReader interface has four things to implement; the Init and Read methods, the IsInitialized property and the ConfigChanges event. The Init method is where you initialize your DSP whether it grabs an XML file or sets a connection to a database. The Read method returns an XmlNode from your storage provider. The IsInitialized property indicates whether or not the CSP as been initialized. If you want to support configuration change events, implement the ConfigChanges event.

The IConfigurationStorageWriter inherits from the IConfigurationStorageReader and adds a method called Write, which accepts an XmlNode as a parameter. This method is intended to save the serialized configuration data to the storage provider. Data Protection Provider Interface
The IDataProtection interface provides the methods necessary to encrypt, decrypt, and sign (hash) data. The four methods that need to be implemented are Init, Encrypt, Decrypt, and ComputeHash.

The Init method initializes the DPP and sets up any necessary variables needed by the specific implementation of the DPP. The Encrypt and Decrypt methods are self-explanatory. The ComputeHash method creates a hash signature of the data provided, which gives you the ability to prevent data from being changed outside of the CMAB. How many times has the configuration settings fairy changed production settings without your knowledge? Now, at least you will know right away. One important thing to note is that the DPP is intended to work with the CSP. Hence the CSP must support and call the DPP interfaces to utilize your DPP implementation with your configuration data.

The Configuration Management Application Block provides a simple, consistent, and robust interface for handling your application configuration data. It comes with a series of out of the box implementations that can be used right away, tweaked to perfection, or tossed out for a custom implementation that you build. Once the interfaces are implemented and configured, the CMAB's use could not be any easier or straightforward. Overall, the CMAB should be able to handle most—if not all—your configuration data needs.

Keenan Newton is a Senior Consultant for Magenic Technologies, Inc., one of the nation's premiere Microsoft Gold Certified Partners, focused on delivering business value through applied technology. He has over eight years of experience designing, architecting, and developing n-tier applications for both Windows and Web environments.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date