Is it possible to know that particular dependency already has been satisfied by ninject
kernel
? To be clear:
Let's suppose we have this module:
Bind<IA>().To<A>();
Bind<IB>().To<B>();
And some "client"-code:
var a = kernel.Get<IA>();
// how to get here "true" for assumption: "IA was requested (once)"
// and "false" for: "IB was not requeste开发者_运维问答d ever"
You could use .Before* and .After* in the fluent bindings to hook in a call to something to mark it used. Or you could look at the IDisposable hooks (see the tests in the source download).
There's good background info in http://kohari.org/2009/03/06/cache-and-collect-lifecycle-management-in-ninject-20/ too
The answer was found here: In Ninject, how can I run custom code on an object after it is created with Bind<..>.ToSelf()?
精彩评论