Cross Container Dependency Resolution

Apr 7, 2010 at 2:58 AM

Hi how can I enable cross container dependency resolution. I have a <dependnecy> tag in one container who's type is registered in an other container? Any help greatly appreciated.

Apr 7, 2010 at 5:39 AM

Boy, you're asking for a world of hurt here. Why do you do this? Can you rearrange things into a parent-child relationship, or just register the type in the container that needs it?

Failing that, you could do something like this:

containerA.RegisterType<TypeInOtherContainer>(new InjectionFactory(c => containerB.Resolve<TypeInOtherContainer>());

but that opens you up for all sorts of weird questions around lifetimes.


Apr 7, 2010 at 7:07 AM

The reason we have 'multiple' containers is: we're an architecture frmaework team, for each piece of functionality we provide we have a corresponding container. So for example we have a help container, MVP container, Services Container, Validation Container etc. However we're also using Unity interception mechanism were we have a few call handlers. Now these call handlers rely on parts of the framework so they need to 'look' into the other containers to fullfil their dependencies (i.e., the physical things that perform the functionality). As we have no idea what call handlers they will use attached to the actual type defined within the corressponding container we can't register everything.