何时在 Ninject 中停用瞬态范围对象?

发布于 2024-08-25 03:18:25 字数 279 浏览 4 评论 0原文

当 Ninject 中的对象与 InTransientScope() 绑定时,该对象不会放入缓存中,因为它是,呃,瞬态的并且没有任何作用域。

处理完该对象后,我可以调用 kernel.Release(obj);它传递到缓存,在缓存中检索缓存的项目并使用缓存的条目调用 Pipeline.Deactivate 。

但由于瞬态对象没有被缓存,所以这种情况不会发生。我无法弄清楚在哪里(或谁)执行瞬态对象的停用。或者是假设瞬态对象仅被激活,并且如果我想要一个可停用的对象,我需要使用其他范围?

When an object in Ninject is bound with InTransientScope(), the object isn't placed into the cache, since it's, er, transient and not scoped to anything.

When done with the object, I can call kernel.Release(obj); this passes through to the Cache where it retrieves the cached item and calls Pipeline.Deactivate using the cached entry.

But since transient objects aren't cached, this doesn't happen. I haven't been able to figure out where (or who) performs the deactivation for transient objects. Or is the assumption that transient objects are only ever activated, and that if I want a deactivateable object, I need to use some other scope?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

诺曦 2024-09-01 03:18:25

你的假设是正确的。瞬态对象不会在 Ninject 中进行跟踪,也不会在停用管道中进行控制。您有责任清理瞬态实例。如果您希望内核管理您的实例,那么您需要使用内置作用域或自定义作用域。

Your assumptions are correct. Transient objects are not tracked in Ninject and not controlled in the deactivation pipeline. It is your responsibility to clean up transient instances. If you want the kernel to manage your instances, then you need to use a built-in scope or a custom scope.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文