Dumping the Container's contents

Feb 5, 2010 at 11:56 AM


we use CAL which comes with Unity. We use child container extensively for defining local contexts for the parts of composite UI. Often, we experience problem that some dependency does not resolve as expected - it is either missing, or it resolves in a parent context instead of child. This usually indicates that something went wrong in the order of initialization, or perhaps of registration.

Long story short - in this cases we need a way to analyze the container at hand. You can examine it field-by-field in a debugger, but it becomes difficult if you have long hierarchies. Is there a way to get container's context (types and instances) and dump it into the debugging output? And do the same with parent and so on until root so that you can understand - what is in the container, which context it represents so that we can try to figure out why it is not in the right state. Any suggestions?



Feb 6, 2010 at 3:31 AM

Unity 1.2 (which ships with the current version of CAL) doesn't really have a way to do this. You could write an extension or poke around inside the internal PolicyList, but I agree, it's not easy. That's why Unity 2.0 includes the container.Registrations property which gives you pretty much exactly what you want. Hopefully we can get a patch out to CAL to support Unity 2.0 fairly soon after release.


Feb 6, 2010 at 5:46 AM

thanks for your reply. Can't wait to see Unity 2.0 within CAL then. When do you think this might happen?



Feb 7, 2010 at 2:58 AM

No idea. The p&p client program team is currently working on other things right now; I'll be discussing it with them, but no idea if / when it'll happen.