Extending EntLibConfig with application's ConfigurationSection (How to implement ConfigurationDesignManager)

Topics: General discussion
Oct 1, 2007 at 4:09 PM
We have an application that stores its configuration in the App.config file, using its custom ConfigurationSection, and are trying to have this configuration editable through the EntLibConfig tool (with Enterprise Library 3.1).

By looking at sample code and various articles, I was able to create a ConfigurationNode and ConfigurationDesignManager that makes it possible to add our configuration in the EntLibConfig tool.

I'm now trying to find the right way to implement the GetConfigurationSectionInfo and OpenCore methods, which, as I understand it, are needed to map from the ConfigurationNode to ConfigurationSection, and also do the reverse mapping (from the ConfigurationSection to ConfigurationNode). If I look at the sample code, I also see that I'll probably need to implement a SettingsBuilder, NodeBuilder and NodeMapRegistrar.

The Enterprise Library help files doesn't give much details on the roles of these methods and classes, or how they should be implemented.
Is there any other document which I could read that would clarify this?

I have also seen some sample code that has its Setting class inherit from the Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SerializableConfigurationSection class instead of
System.Configuration.ConfigurationSection class.

What additional functionality does the SerializableConfigurationSection provide (isn't a ConfigurationSection already serializable?).
Is it mandatory to inherit from SerializableConfigurationSection in order to use the EntLibConfig tool?

Thanks
Oct 1, 2007 at 4:22 PM
Hi,

You will probably find this webcast from Brian Button very helpful http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032291157&Culture=en-US. Also, using the App Block Factory will make the task much easier.

Regarding the SerializableConfigurationSection, it enables storing configuration to media other than files.

Regards,
Fernando
Oct 1, 2007 at 10:20 PM
Thanks,

I just watched the webcast and unfortunately it only confirms my understanding (it confirms I was doing the right things), it did not give me the additional information I was looking for.

I have a solution that's almost functional, but have some problems to work out. For this, I would need a better understanding of the EntLibConfig tool's architecture, to make sure my implementations are correct. Therefore, I'm looking for more detailed documentation. Is there a document (or book) I could read about this? The help file is not really useful, as it only contains documentation generated from the source code, with a few vague descriptions.

For example, for the ConfigurationDesignManager.GetConfigurationSectionInfo method, it only says: "Gets the a ConfigurationSectionInfo for the configuration for this design manager". After looking at examples, I was able to understand that its real role would be "Translates a UI ConfigurationNode to the corresponding runtime ConfigurationSection class". Is there any document that would give that kind of information?

I also tried the App Block Factory and it's probably a nice tool to use once you understand what a method should do, but not when initially learning the architecture.

The webcast would probably have been a nice introduction if I had found it earlier, so I'll keep it as a reference when introducing other people to the Enterprise Library Configuration. The webcast also mentions it is the second part of another webcast. Do you have a link to that initial webcast?

However, I would also prefer written documentation because it's easier to refer to a location in a document than to search for a specific instant in a webcast when looking for some specific information.
Oct 2, 2007 at 12:35 PM
Hi,

There's Lenny Fenster's book, but unfortunately it's mainly about EntLib 1.1. There is also a new book that has not been released yet titled "The Definitive Guide to the Microsoft Enterprise Library", but the TOC is not available so I don't know the kind of treatment it gives to this subject. I'm not aware of an in-depth document about this.

Fernando
Oct 2, 2007 at 2:50 PM
Hi,

I already looked at Lenny Fenster's book, but its information about the Configuration Application Block is mostly outdated (since this has been partially replaced by System.Configuration in Enterprise Library 2.0)

I was not aware of "The Definitive Guide to the Microsoft Enterprise Library", but I'll get a copy once it's available.

I was hoping there was a more complete document I had not seen, but if not I'll keep looking at the examples (and post my questions here) to find what I was doing wrong.

Question:
There's one thing I noticed while debugging my ConfigurationDesignManager :
When I open a configuration file in the EntLibConfig GUI, my GetConfigurationSectionInfo() method is called. What is the reason for this call?
Is the role of this method only to map from a SettingsNode to a ConfigurationSection class?

Since it's called even when there is no configuration loaded (and therefore no mapping from SettingsNode to ConfigurationSection to do), this suggests the method also has another role.


Here's my implementation of the method:
protected override ConfigurationSectionInfo GetConfigurationSectionInfo(IServiceProvider serviceProvider)
{
ConfigurationNode rootNode = ServiceHelper.GetCurrentRootNode(serviceProvider);
MySettingsNode settingsNode = null;
MySettings settings = null;

if (null != rootNode) settingsNode = rootNode.Hierarchy.FindNodeByType(rootNode, typeof(MySettingsNode)) as MySettingsNode;
if (settingsNode != null)
{
MySettingsBuilder builder = new MySettingsBuilder(serviceProvider, settingsNode);
settings = builder.Build();
}

return new ConfigurationSectionInfo(settingsNode, settings, MySettings.SectionName);
}

With this implementation, when GetConfigurationSectionInfo() is called when opening a configuration file, it returns a ConfigurationSectionInfo with a null settingsNode and null settings. Is that the right thing to do? Are there other possibilities?

Thanks
Oct 3, 2007 at 1:38 PM
Hi,

Answers inline


Question:
There's one thing I noticed while debugging my ConfigurationDesignManager :
When I open a configuration file in the EntLibConfig GUI, my GetConfigurationSectionInfo() method is called. What is the reason for this call?
Is the role of this method only to map from a SettingsNode to a ConfigurationSection class?

Since it's called even when there is no configuration loaded (and therefore no mapping from SettingsNode to ConfigurationSection to do), this suggests the method also has another role.


It seems to be the way to retrieve the section name, regardless of whether the settings node was converted into a config section.


Here's my implementation of the method:
protected override ConfigurationSectionInfo GetConfigurationSectionInfo(IServiceProvider serviceProvider)
{
ConfigurationNode rootNode = ServiceHelper.GetCurrentRootNode(serviceProvider);
MySettingsNode settingsNode = null;
MySettings settings = null;

if (null != rootNode) settingsNode = rootNode.Hierarchy.FindNodeByType(rootNode, typeof(MySettingsNode)) as MySettingsNode;
if (settingsNode != null)
{
MySettingsBuilder builder = new MySettingsBuilder(serviceProvider, settingsNode);
settings = builder.Build();
}

return new ConfigurationSectionInfo(settingsNode, settings, MySettings.SectionName);
}

With this implementation, when GetConfigurationSectionInfo() is called when opening a configuration file, it returns a ConfigurationSectionInfo with a null settingsNode and null settings. Is that the right thing to do? Are there other possibilities?


This is consistent with the other managers. One aspect that differs is that most managers also deal with the protectionProvider; you may want to do it too.

Fernando