Dependency injection and life time of IDisposable objects

百般思念 提交于 2019-12-05 16:16:18

You need to use either the CallScope or the NamedScope. These are part of the Ninject.Extensions.NamedScope package. This allows you to scope the common object to the parent so all child requests receive the same common.

Regarding the child object creation. If you have to request child objects depending on some algorithm you need to instantiate it with a factory. Use the Ninject.Extensions.Factory package to achieve this. This does a context preserving get and passes the parent context to the child request and therefore allows to reuse your common object also in the children which are created by the factory.

So in the end there will be no need to use your own object factory.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!