Question

I'm using Ninject 3 on .NET 3.5 Compact Framework.

I have an application that uses various things bound using InSingletonScope().

For debugging purposes, I need to know which singletons have been actually activated... which bindings have been requested and resolved, and which singletons are actually instanced.

I can find no way to get the list of currently active singleton bindings. I also can't find a way to get the complete list of bindings to iterate them.

I did see a post that mentioned I should be able to call kernel.Get<ICache> to get the cache object that holds the instances, but that call gives me an activation exception saying that nothing is bound to ICache and it's not self-bindable. Note that I'm attempting to retrieve the ICache object after I know for a fact a singleton has been created, so it's not something stupid like no instances have been created yet.

It's a really simple configuration. It's a single module that is loaded with about a dozen or so mappings all mapped to corresponding interfaces with InSingletonScope(). I just need to get the list of what has actually been instanced.

Is there some way to get the list of singleton bindings that are currently loaded? Again, this is for debugging purposes only.

Thanks for the help.

Was it helpful?

Solution

ICache is registered as a ninject component. IKernel.Components.Get<ICache>() should do the trick.

There is no "easy out of the box" way to either retrieve bindings or all activated singletons. However the ICache should hold references to all singletons so you should be able to retrieve the instanciated singletons from there.

But you will need use reflection since the cached values are not publicly accessible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top