Multiple IoC containers

Topics: Bootstrappers & IoC
Mar 7, 2012 at 9:04 AM


I'm developing an application which contains a shell hosting different modules. The modules are loaded using MEF. The shell is using MEF as the IoC container.

Right now all the exports added in the shell's bootstrapper is available in the modules, but I tried to add a separate "module" bootstrapper in a module which also was based on Caliburn but with another IoC container. The reason is that I want the module to be able to run stand-alone.

Shell bootstrapper:
- Caliburn

Module A bootstrapper
- Caliburn
- Ninject 

However, when I load module A it swap the IoC container from using MEF to Ninject, meaning that the shell is now broken. I guess this is by design because the IoC is static in Caliburn, but is it possible to use Caliburn in different modules using different IoC containers?


Mar 7, 2012 at 4:42 PM

You would need a way to determine the correct IoC container based on the call context. If you could come up with a mechanism like that, you could override the bootstrapper methods to select the correct container and use that to serve up the services.

Mar 8, 2012 at 8:31 AM

Okay, I will look into the source code and see if it's possible to create some sort of mapping.