First of all, I am amazed at the community that has already built up around Enterprise Library.  You guys are awesome.  For any of you going I will be at Vs Live next week and any one that wants to have some face time come to the Enterprise Library talk given by Ron Jacobs and I will be hanging around afterwards.  If you have any feedback, want to dive into some code, etc., please come by and see me. 

Important Stuff Here
To work with what I am going to talk about you will need to patch Enterprise Library with patch 1462 (don’t worry we hadn't patched it 1462 times, this is just our internal build number) found here (http://www.gotdotnet.com/workspaces/workspace.aspx?id=295a464a-6072-4e25-94e2-91be63527327).  I found this problem when writing this post, so this is why it has taken me a while to get it out .

As I talked about before, a storage provider is an extension point that allows you to store your meta-configuration in another physical store.  The following interfaces are involved in creating a storage provider : IStorageProviderReader, IStorageProviderWriter, IConfigurationChangeWatcherFactory, and IConfigurationChangeWatcher. I will try to explain each one of these without regurgitating the existing documentation.

IStorageProviderReader
The IStorageProviderReader interface allows you to create a read only provider to your storage. We wanted to separate this out so if you have requirements that configuration is only read at runtime and written at development / deployment time you could separate this functionality and support the scenario.  For example, you want to make sure you don’t have code out there arbitrarily changing configuration information in the file, you only want to give this support to operators in your data center.

IStorageProviderWriter
The IStorageProviderWriter interface is the inverse of the IStorageProviderReader interface. Now I doubt you would implement a write only storage, but hey what do I know?

IConfigurationChangeWatcherFactory
The IConfiguraitonChangeWatcherFactory is interesting.  We needed / wanted a way for the storage provider to notify us when the underlying storage changed externally (heck we know when you do it through code ).  We wanted to separate the the responsibility of reading and wring to storage from watching for changes, so we created the interface and had the IStorageProviderReader interface implement it so when we find your IStorageProviderReader, we can query for an IConfigurationChangeWatcherFactory to get your implementation for an IConfigurationChangeWatcher.  (Did I just say query… oh my COM days are bleeding through ).

IConfigurationChangeWatcher
The IConfigurationChangeWatcher is an interface that allows you to create an object that will watch for external changes in your configuration store.  You will always need to create one and return one or an exception will be thrown.  This “feature” will probably be changed in the future.  So if you don’t want / need an IConfigurationChangeWatcher, then you should create a null one that would look something like this: 

   1:  public class NullConfigurationChangeWatcher : IConfigurationChangeWatcher
   2:  {
   3:      public NullConfigurationChangeWatcher()
   4:      {
   5:      }
   6:   
   7:      public event ConfigurationChangedEventHandler ConfigurationChanged;
   8:      
   9:      public void StartWatching(){}
  10:   
  11:      public void StopWatching(){}
  12:      
  13:      public string SectionName
  14:      {
  15:          get { return "MySectionName"; }
  16:      }
  17:   
  18:      public void Dispose(){}
  19:  }
 

In the section name you would return your configuration section name.

Enterprise Library Implementation of Storage Providers
For our implementation of a Storage Provider, we chose to store each configuration in a separate file. Our thinking was that in a server side scenario you don’t want to touch the app.config file especially web.config so the whole ASP AppDomain does not tear down.  The Storage Provider is implemented in the XmlFileStorageProvider.  This guy just reads the Xml as a node to pass back up the chain. Now since we create strongly typed object graphs, we use the XmlSerializer in our transformer so we can serialize and deserialize the XmlNode. More on this in the next post.

New Storage Providers
Now for what you all have been waiting for… a new storage provider.  Since Peter has been bugging me since he started working on Enterprise Library for writing all the configuration to the single application configuration file, I finally did it. The main detail you need to know is that this storage provider will not work with the designer.  I will be posting a designer for this storage provider sometime in the next few days.  To see it work, run the unit tests and then look at the configuration file in the output directory to see it’s output.

Download the sample from the release section in the GotDotNet workspace Releases section.

Now playing: Zero 7 - In the Waiting Line