Enterprise Library : Configuration Part 1
As Peter Provost says to me all the time “it is all about configuration, that is what it [Enterprise Library] essentially is…”. I guess he is right. Since Enterprise Library [EntLib] is built to be extensible, pluggable, etc., we needed a mechanism to allow for these requirements. The default Configuration system in the .NET framework allows you read configuration from your application config file (app.config / web.config), yet it provides no mechanism for any other storage and it works with IConfigurationSectionHandler instances which may not be rich enough for your requirements. Enterprise Library doesn’t try and replace this functionality but rather give you another option if you need it that fills some of the requirements from Enterprise customers that we (patterns & practices) have identified.
Configuration is separated into two separate physical and logical concepts : Runtime and Design-time. I will attempt to explain these things at a high level and then in future posts drill down on the individual concepts in more detail. So forgive me if I start to high, don’t worry we will reach terminal velocity pretty soon.
Runtime
The runtime version of configuration is where the bulk of the work happens. There are three concepts going on here, meta-data configuration, storage and transformation. Meta-data configuration is the term we use to describe the configuration information that will express a blocks particular configuration requirements. Storage allows for reading and writing your configuration and transformation allows you to transform the data from storage into a specific format.
In a normal configuration file it would look something like the following:
1: <?xml version="1.0" encoding="utf-8" ?>
2: <configuration>
3: <configSections>
4: <section name="someName" type="someType" />
5: </configSections>
6: <appSettings>
7: <add key="MyKey" value="MyValue" />
8: </appSettings>
9: </configuration>
We have added our own IConfigurationSectionHandler that allows us to define the meta-data configuration. Here is what your configuration will look like when you add any library from Enterprise Library :
1: <?xml version="1.0" encoding="utf-8" ?>
2: <configuration>
3: <configSections>
4: <section name="enterpriselibrary.configurationSettings"
5: type="Microsoft.Practices.EnterpriseLibrary.Configuration._
6: ConfigurationManagerSectionHandler,Microsoft.Practices._
7: EnterpriseLibrary.Configuration" />
8: </configSections>
9: <enterpriselibrary.configurationSettings
10: xmlns:xsd=https://www.w3.org/2001/XMLSchema
11: xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
12: xmlns="https://www.microsoft.com/practices/enterpriseli_
13: brary/08-31-2004/configuration">
14: <configurationSections>
15: <configurationSection name="ApplConfig1">
16: <storageProvider xsi:type="XmlFileStorageProviderData"
17: name="XmlStorage" path="myconfig.xml" />
18: <dataTransformer xsi:type="XmlSerializerTransformerData"
19: name="XmlTransformer" />
20: </configurationSection>
21: </configurationSections>
22: </enterpriselibrary.configurationSettings>
23: <appSettings>
24: <add key="MyKey" value="MyValue" />
25: </appSettings>
26: </configuration>
Now you can see that we have our own namespace in here that define your configuration settings (meta-data configuration). The configurationSections element now allows you to define specific named configurationSection elements that contain the meta-definition of your configuration.
The first thing you will notice is the storageProvider element. This is the storage provider you define that reads and/or writes data to a physical storage location (for example a file). The next thing is the dataTransformer element. This is the transformer you define to take data from storage and format to the specification for your application and then take the data from the application and format it so the storage provider can save the data back to the physical store. The transformer is not required, you can just have the object returned from the storage provider returned directly to your application (for example, a DataSet).
In summary (and at a high level), the runtime enables you to have configuration for your application that does not tie you to just your app.config file. Now those that have been paying attention will notice that I am of the opinion that xml is not a programming language but just self describing storage . I know that some of you are saying, wow you mean I have to start typing all this xml goop (a very technical word) by hand for my applications? Well I am glad you asked, and the answer is a resounding no. You can still edit by hand, but that is no longer necessary .
Design-time
The design-time configuration infrastructure is two fold : the library to help you build the plug-ins for the tool and the tool itself. Before we go to far, the following is a picture of the tool:
You can call this a meta-data editor (I took this picture on a Win2K3 box without themes). As you can see we have a few blocks in here : Caching, Configuration and Data. All the tool knows how to do is look for an assembly level attribute and load your design-time editor into itself. This is where the design-time library helps you out. It gives you the base classes and helpers to wire all your designers up using a good portion of the System.ComponentModel namespace. The tool works similarly to the MMC console and can be used by developers and operators in your organization. We were hoping to have an integrated environment for Visual Studio, but of course we have to stop sometime and ship the thing… so stay tuned for that in V2.
As they say, pictures speak a thousand words, so I will leave the design-time for now.
I hope these little blog postings will help everyone get comfortable with using EntLib. Stay tuned for the next posting where we will be drilling down into the internals of the Configuration Runtime….
Now playing: Queens of the Stone Age - No One Knows
Comments
Anonymous
January 28, 2005
The comment has been removedAnonymous
January 28, 2005
Well, their was some internal strife that caused us not to commit to MMC just yet (hopefully we can do it in V2). Also, you can open files from anywhere as long as you the correct permissions. You can also open multiple applications in the same session... very soon you will see.Anonymous
January 28, 2005
The East Coasters are getting antsy.Anonymous
January 28, 2005
The comment has been removedAnonymous
January 28, 2005
IDictionaryService .. pardonAnonymous
January 28, 2005
practices homepage says: http://msdn.microsoft.com/library/en-us/dnpag2/html/entlib.asp
currently 404s for meAnonymous
January 28, 2005
The link seems to be working fine now, at least for me. Thank you Scott, it looks great.Anonymous
January 30, 2005
I can't seem the images, is there a reason for that?Anonymous
January 30, 2005
never mind about the previous question, it's our firewall.
thanksAnonymous
February 03, 2005
Hi,
I'm trying to use this to store key-value pairs, as I used extensively with the former application block, but can't seem to find out how. Are there any examples out there (the included ones seem to implement custom classes, but I don't need it).
GAnonymous
February 05, 2005
URGENT QUESTION: How do you configure a Data Access connection string in a web application? I can't figure out what the configuration file should be or where. Also, I couldn't find examples for a user/password type of connection string.
Thanks!
Uri.Anonymous
February 09, 2005
QUESTION: How do I extend the configuration to encrypt part or all of an XML configuration file?Anonymous
February 10, 2005
The comment has been removedAnonymous
February 15, 2005
Hello Scott,
On your comment:
"Well, their was some internal strife that caused us not to commit to MMC just yet (hopefully we can do it in V2)."
We would like to develop many administrative tools, probably using MMC and C# architecture. So if you recommend ussing MMC and C#, would you have an example on this? Or should we use the architecture you are using in Configuration block (not mmc).
But you are also saying that hopefully version 2 will be MMC. and that you haad some internal strife.. So could you elaborate more on this? This is kind of urgent to us.
When is V2 comming out? do you have any examples on MMC and C# that are as complete as the configuration block tool?
Thanks for you help.
Cordially,
Luis
luisg_gonzalez@hotmail.comAnonymous
February 17, 2005
Here is the list of links from .NET Musings: Enterprise Library Configuration Part 1 http://weblogs.asp.net/scottdensmore/archive/2005/01/28/362579.aspx Enterprise Library as non-Admin http://weblogs.asp.net/scottdensmore/archive/2005/01/29/363202.aspx Manage Application Settings Using Enterprise Library Configuration http://blog.hishambaz.com/archive/2005/01/30/197.aspx Logging with Enterprise Library http://blog.hishambaz.com/archive/2005/01/30/202.aspx Enterprise Library Logging - Rolling File Sink...Anonymous
February 24, 2005
The DAAB doesn't seem to recognise the standard SQL "User ID" and "Password" configurations, it seems to want "user" and something else for "Password", I have tried "PWD" but it doesn't like that.
There is no relevant documentation on this monster. Why couldn't they just use what we are all used to: "User ID" and "Password" ?Anonymous
February 26, 2005
The comment has been removedAnonymous
February 26, 2005
jasper
Actually after looking a little further, the values are not case sensitive.
Sorry about that..
scottAnonymous
March 12, 2009
PingBack from http://justmyopinion.cilyok.net/?p=50Anonymous
June 08, 2009
PingBack from http://cellulitecreamsite.info/story.php?id=9226Anonymous
June 18, 2009
PingBack from http://thestoragebench.info/story.php?id=7995