Armed with our knowledge of XML Serialization, we can certainly start creating a solution for accessing and persisting global settings in our ASP.NET application. However, we may want to back up a bit and look at the Configuration Application Block created by the Microsoft Patterns and Practices Group. Even if we decide not to use the application block, we certainly want to at least understand how it works so we can justify our decision to our boss or client - but even more important, the guys at the next .NET Pub Club or Code Brew meeting!
After reading the documentation, one essentially runs the Enterprise Library Configuration Application to help create the configuration information that needs to be placed in the application's config file.

Notice that the application block comes with an XML File Storage Provider and an XML Serializer Transformer. Heck, this sounds like XML Serialization to me, so learning it was time well spent.
After making the configurations and saving the results, we end up getting two files: configtest.config (with the configuration information) and a blank sitesettings.config file. The configuration information looks like this:
I copy over a couple of the Configuration Application Block DLL's as shown above and run Snippet Compiler to test it out. Here is the code:
Here is the now populated sitesettings.config file with the global application settings:
This looks like the same output as the previous XML Serialization Example. Man, this is sweet! Not only are the results basically the same, but I have totally abstracted the storage of the global application settings so that I could change it in the future. Notice that all my references to anything concerning XML are gone. I like this better. Besides, anytime you can use the word "Enterprise" in a sentence has got to be worth something :)
Posted
Wed, Mar 2 2005 10:31 AM
by
David Hayden