Note 1: I want to make this clear: I am not trying to lazy load dependencies or inject lazy types.
Most (all?) IoC containers require metadata to be registered with the container to describe how some type should be resolved when asked; this includes the implementation of an interface, the lifetime of the object, etc. Over the past couple of years, the fluent/convention based APIs have been added to most (all?) IoC containers which reduces a lot of the noise when providing this metadata to the container.
With ninject, I am using a conventions based approach to register my metadata, but I do it on demand, not upfront. This yields huge performance savings in an integration test scenario where you are creating ~10 objects; you lose the overhead of having to register the entire application's dependencies every test.
Note 2: Please do not tell me that you should not use an IoC container in an integration test.
There is some pressure to move to using Microsoft components when available, so Unity is on my horizon. I have the conventions based registration working, but I cannot figure out how to "discover" this metadata on demand/lazily like I could in Ninject.
My first attempt to implement this was using a wrapper around the UnityContainer instance, and upon calling GetInstance(type) on the wrapper, I can query the container to see if the type is registered. If not, I can invoke my conventions, discover the metadata, and register the type. This approach only goes one level deep however; if that type is injected with more dependencies, each dependency does not get fed back into the GetInstance(type) method, and thus, my dilemma.
The question: How can I lazily/on-demand add type registrations to Unity?
Source would be nice, but a pointer to a hook in the container would be just as good. I tried inheritance but there is nothing to override like in Ninject.