Environmental Overrides in Enterprise Library 3.0 - Managing Development, Test, Staging, and Production Configurations Made Easy!

Environmental Overrides in Enterprise Library 3.0 - Managing Development, Test, Staging, and Production Configurations Made Easy!

by David Hayden ( Florida .NET Developer ), Filed: Enterprise Library 3.0

 

One of the new features unveiled in the Feb 2007 CTP of Enterprise Library 3.0 is Environmental Overrides, which allows you to manage different Enterprise Library Configuration Settings for different configuration environments: Development, Test, Staging, Production, etc. So often you want to have a default configuration environment that acts a base for all environments but then adjust / override certain settings that may be particular to a certain environment.

A good example may be a connection string for the database. Often each environment has its own database server and you want to be able to specify a different connection string for each environment. However, as this may be the only difference, you don't want the headache of managing several configuration files independently and having to keep them synchronized. The new Environmental Overrides Functionality in the Enterprise Library 3.0 Configuration Tool allows you to manage these configuration differences easily without the headache of managing and synchronizing independent configuration files.

 

Environmental Overrides in Enterprise Library 3.0

The image below shows the new Environments Configuration Node that is available in the Enterprise Library Configuration Editor. If you have separate Test and Production Environments and there are differences in the configurations, you could specify a separate environment for each.

 

Environmental Overrides in Enterprise Library 3.0

 

In my simplified case, I have a different database ( connection string ) that I use for Test and Production. You can do this any number of ways, but I have chosen to add the connection string for the Test Database as the default and override the setting to the Production Database for the Production Environment.

 

Environmental Overrides Connection String in Enterprise Library 3.0

 

As you can see above, as you add new environments to your configuration file you start getting the ability to override properties by environment. Now when I go to my Connection String node, I have the ability to specify an override Connection String for each environment. In this case, I specified a different connection string to point to my Production Database for the Production Environment.

The overrides for each environment are stored in a separate delta configuration file. My Production Delta Configuration File looks as follows and specifies the override of the Connection String:

 

<configuration>
    <configSections>
        <section name="EnvironmentMergeData" type="Microsoft.
Practices.EnterpriseLibrary.Configuration.
EnvironmentalOverrides.Configuration.
EnvironmentMergeSection, Microsoft.Practices.
EnterpriseLibrary.Configuration.
EnvironmentalOverrides, Version=2.9.9.2,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
" /> </configSections> <EnvironmentMergeData environmentName="Production"
environmentDeltaFile="Production.config"> <mergeElements> <override nodePath="/Data Access Application Block/
Connection Strings/Connection String
" overrideProperties="true"> <overridddenProperties> <add name="ConnectionString"
value="Data Source=.;Initial
Catalog=Production;Integrated
Security=True
" /> </overridddenProperties> </override> </mergeElements> </EnvironmentMergeData> </configuration>

 

The delta file holds the changes / overrides from the main configuration file. When you want to merge the changes with the main configuration file and produce the Production Configuration File you do it as follows:

 

Merge Environmental Overrides in Enterprise Library 3.0

 

You gotta love it!

Conclusion

Managing Enterprise Library Configuration Files for Development, Test, Staging, and Production environments is now much easier.

Come see me at the Orlando Code Camp on March 24, 2007 as I present all the new features in Enterprise Library 3.0.

Source: David Hayden ( Florida .NET Developer )

Filed: Enterprise Library 3.0

 

posted on Thursday, March 01, 2007 6:10 PM

My Links

Post Categories

Article Categories

Archives

Loose-Leaf Tea