Having Unity Pick up EntLib's Configuration Source

Topics: Enterprise Library Core, General discussion, Policy Injection Application Block
Apr 20, 2011 at 7:34 PM

What's the easiest way to configure Unity to pick up the EnterpriseLibrary's configuration source? I have an alternative configuration file as the source, which the instance of Unity in the default container can pickup for resolving Enterprise library objects, but it will only pickup declarations of my objects from the app.config file.

Apr 21, 2011 at 6:15 AM

Assuming you've already constructed another configuration source (FileConfigurationSource for example), then the easiest way to get a container to pick up the registrations would be:

var container = new UnityContainer()
    .AddExtension(new EnterpriseLibraryCoreExtension(configSource));

That will give you a container that's configured with Entlib out of whatever config source you're using. If you leave out the parameter, it'll use the default app.config.

You can also then load a Unity configuration section into the same container to pick up whatever other registrations you might need, or use the Unity API or whatever.