Share via


About the Configuration System

Enterprise Library first looks at the default configuration file (the current application domain configuration file). This will be either your App.config file (which is copied to [exe-name].config when you compile your application) or your Web.config file. This file may contain a configuration section that defines additional configuration sources. The core configuration classes that support reading configuration information first try to read the requested configuration section from the configured source location.

The enterpriseLibrary.ConfigurationSource section in the configuration file carries the selectedSource attribute, which specifies the configuration source that the application should use. The <enterpriseLibrary.ConfigurationSource> section is retrieved from the current application domain's configuration file, and Enterprise Library uses the configuration information exposed by the configuration source specified by the selectedSource attribute.

Ff664549.645f9405-701d-4bc7-9f72-39761017c708(en-us,PandP.50).png

The source defined by the selectedSource attribute could be any of the following sources:

  • A System Configuration Source, which reads from the application's configuration file.
  • A File-based Configuration Source, which reads from an arbitrary file.
  • A Manageable Configuration Source, which reads from an arbitrary file and applies group policy overrides, or any custom configuration source.
  • The sample SQL Configuration Source available from the Enterprise Library Contrib Project Web site, which reads configuration data from a database.
  • A custom configuration source that you create and add to Enterprise Library.

If there is no <enterpriseLibrary.ConfigurationSource> section in the configuration file, an instance of the SystemConfigurationSource class is used by default and becomes the application configuration source.

Note

Configuration sources are an extensibility point in Enterprise Library.

The following XML fragment shows a configuration section that specifies Enterprise Library should read configuration information using the File Configuration Source.

<enterpriseLibrary.ConfigurationSource selectedSource="fileSource">
  <sources>
    <add name="fileSource"
         type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource,
              Microsoft.Practices.EnterpriseLibrary.Common"
         filePath="test.exe.config"/>
    <add name="systemSource" 
         type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource,
              Microsoft.Practices.EnterpriseLibrary.Common"/>
  </sources>
</enterpriseLibrary.ConfigurationSource>

Redirection and Inheritance Configuration Property and Attribute Settings

The following table lists the configuration redirection and inheritance settings available in Enterprise Library.

Name in configuration tools

Attribute in configuration

Description

Configuration Source and Sources section


Contains a list of configuration sources that can be referenced by name. Enterprise library can read configuration content from these configuration sources.

Redirected Section(s)

redirectSections

Contains a list of sections (such as a complete application block section) that will be redirected to another configuration source, which will override any local configuration for that section.

Selected Source

selectedSource

Specifies the configuration source that the Enterprise Library configuration classes should use to read configuration information.

Parent Source

parentSource

Specifies the configuration source that the Enterprise Library configuration classes should use to read inherited configuration information that the local configuration may override.

Saved Configuration Settings

When saving a configuration in the configuration tool, information about the configuration sources is saved to the <enterpriseLibrary.ConfigurationSource> section of the application configuration file, while the application block configuration sections such as <exceptionHandling> and <securityCryptographyConfiguration> are saved to the file specified by the value of the selectedSource attribute of the <enterpriseLibrary.ConfigurationSource> element.

When the Selected Source is not set to the default SystemConfigurationSource, only the application block configuration sections are saved to the alternative file specified by the Selected Source attribute. If you want to use redirected sections or a parent configuration source in combination with a selected source, open the selected source using the configuration tool and add update these settings in the selected configuration source.

Note

The configuration tools display the following message when saving with selectedSource set to anything other than System Configuration Source and you specify redirected sections and/or a parent source: "Using both Redirected Sections and a Selected Source other than System Configuration Source will persist the Redirected Sections in the current configuration file. If the expected result is to redirect from within the Selected Source, open the Selected Source and add the redirects locally."