Alternative configuration file without app.config?

Topics: Enterprise Library Core
Jul 9, 2010 at 9:51 PM

I've been looking to see if there's a way of having alternative configuration file without declaring enterpriseLibrary.ConfigurationSource section.

My code to configure EnterpriseLibraryContainer is; 

FileConfigurationSource fileSource = new FileConfigurationSource("unity.config");
UnityContainerConfigurator configurator = new UnityContainerConfigurator(new UnityContainer());
EnterpriseLibraryContainer.ConfigureContainer(configurator, fileSource);

This works fine when I have the section in the app.config, but I'd like to know if there's a way to configure without app.config section.

Is it possible?

Jul 12, 2010 at 2:34 AM

Hmm, there seems to be a problem because this code works for the other application blocks even without defining the configuration source in the enterpriseLibrary.ConfigurationSource section.  It doesn't work for unity configuration section.  I'll investigate more about this and let you know when I find out something.


Sarah Urmeneta
Global Technology & Solutions
Avande, Inc.

Jul 12, 2010 at 3:17 AM

You can use this code:

IConfigurationSource fileSource = new FileConfigurationSource("unity.config");
IUnityContainer container = new UnityContainer();

UnityConfigurationSection configSection = (UnityConfigurationSection)fileSource.GetSection("unity");
configSection.Configure(container); //for loading default container or configSection.Configure(container, "Base"); for loading container named "Base"

Sarah Urmeneta
Global Technology & Solutions
Avande, Inc.