开发者

How to get if the object is already retrieved in inject

开发者 https://www.devze.com 2023-01-02 11:43 出处:网络
Is it possible to know that particular dependency already has been satisfied by ninject kernel? To be clear:

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()?

0

精彩评论

暂无评论...
验证码 换一张
取 消