Take the 2-minute tour ×

In my project there is some common package which gets its dependencies resolved by the UnityContainer which is defined in unity.config file. There is another custom package which I want to have its own custom UnityContainer in a seperated CustomUnity.config file.

In runtime I want both files to be loaded and when I get the unity section, I want it to contain both UnityContainers.

How can i achieve it?


share|improve this question
add comment

2 Answers

The UnityContainer.LoadConfiguration method can be called multiple times on the same container. Each time it loads whatever's in that configuration section, but it doesn't remove what was previously in the container - it's additive. If there's a conflict (both sections configure the same type) then last one in wins.

So, the approach would be to use the ConfigurationManager APIs to load your two separate UnityConfigurationSections, and then call LoadConfiguration twice, once for each configuration section. That should be all you have to do.

share|improve this answer
add comment

I wrote a library that lets you write your ioc container configuration in modules. It supports unity but you will have to configure your container in codes instead of using the files. I don't know if will solve your problem, but you can check it out at bootstrapper.codeplex.com

share|improve this answer
add comment

Your Answer


