Configuration Sources: Can my Parent Source have a Parent Source of its own?

Topics: Enterprise Library Core
Jan 22, 2014 at 4:55 PM
Edited Jan 22, 2014 at 5:03 PM
Using Ent Lib 5.0 (5.0.414.0). I have a solution with many applications, these have App.Config and Web.Config files. The App/Web.Config files share a common Parent Source, named "The Master", using the Ent Lib <enterpriseLibrary.ConfigurationSource> feature. This works well.

I now need to add another layer to the configuration hierarchy and had assumed I could setup the Master config file with a parent source of its own again using <enterpriseLibrary.ConfigurationSource> but it’s not working. Problem is, I can’t tell if I have my XML wrong or if this is unsupported by Ent Lib.

I’ve stepped into the Ent Lib source with the debugger as best I could and while I don’t understand each step, I did see Ent Lib load the Parent Source of my App.Config. But it seemed to ignore the Master’s <enterpriseLibrary.ConfigurationSource> section and didn’t load its parent, let’s call it the Grand Master ;-).

Here’s what my config files look like, I’m hoping my XML is simply wrong, I know it needs to be just right.

The App/Web.Config looks like this:
<configuration>
...
  <configSections>
    <section name="enterpriseLibrary.ConfigurationSource".. />
    <section name=".." .. />
  </configSections>
...
  <enterpriseLibrary.ConfigurationSource selectedSource="System Configuration Source" parentSource="Master Configuration">
    <sources>
      <add name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, ..." />
      <add name="Master Configuration" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, ..." filePath="...\Master.App.Config" />
    </sources>
  </enterpriseLibrary.ConfigurationSource>
...
The Master Looks very much the same, I added the following, I tried different names, in case I had clashes, but still no go:
<configuration>
  <configSections>
    <section name="enterpriseLibrary.ConfigurationSource".. />
    <section name=".." .. />
  </configSections>
...
  <enterpriseLibrary.ConfigurationSource selectedSource="Master Configuration Source" parentSource="Grand Master Configuration">
    <sources>
      <add name="Master Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, ..." />
      <add name="Grand Master Configuration" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, ..." filePath="...\Grand.Master.App.Config" />
    </sources>
  </enterpriseLibrary.ConfigurationSource>
...
Thank you,
Martin.
Jan 23, 2014 at 6:37 AM
Unfortunately, according to the Merge Rules for Inherited Configuration:

Inheritance can only be one level deep; you cannot define a parent source for a configuration source that is itself used as a parent source. This prevents the accidental creation of circular references and endless recursion.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Jan 23, 2014 at 1:25 PM
Thank you for the reply and the confirmation, we'll find an alternative way to implement what we need.

I do however suggest that the Ent Lib team consider allowing inheritance to be more than 1 level deep. “hierarchical configuration” (from wikipedia and elsewhere) is a documented feature of Ent Lib but a single parent is not really a hierarchy, it’s a parent. As for “preventing the accidental creation of circular references and endless recursion”, I think we can handle it, we are big boys/girls and if we create an endless loop, we’ll find it. The value of such a feature is worth the risk.

Martin.