OpenRasta 依赖注入拆解
OpenRasta 中的依赖注入器中是否有一种机制可以销毁所创建的对象的实例?无论依赖生命周期如何。
我尝试查看源代码,但无法直接找到任何可拆卸的内容。实施 IDisposable 似乎也无法解决问题。
更新 我主要是在寻找处理单例,所以我不会在 openrasta-core 项目上开票。目前,我在自己的库中跟踪单例的实例(目前不知道如何直接访问 OpenRasta 中的单例),以便在应用程序关闭时进行访问。
Is there a mechanism in the dependency injector in OpenRasta that tears down the instance of an object that is created? Regardless the dependency lifetime.
I tried looking through the source, but could not directly find any tear down. Nor seems implementing IDisposable do the trick.
Update I was mainly looking for disposing a singleton, so I won't be opening a ticket on the openrasta-core project. For the moment I keep track of the instance of the singleton in my own library (currently not knowing how to access singletons in OpenRasta directly), to access upon application close.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正确实施处置是一件很痛苦的事情。每个请求的对象都有一个已知的对象生命周期(实现 OR DI 接口的容器有一个钩子来知道何时处置该范围),静态(自 2.1.1 起)将由容器在主机关闭时处置(这意味着对于asp.net来说几乎从来没有,每当你关闭自托管服务器/在mem托管中),并且瞬态我们不知道如何做到这一点:如果你不跟踪,你怎么知道什么时候必须处理某些东西其中,如果你这样做就意味着它不会被释放,这都是非常有问题的。
因此,内部 DI 容器根本不会处理任何内容,尽管我们可以在容器处理上添加单例处理,并在请求关闭时添加每个请求的处理,我想这会非常有用。请随意在 openrasta-core 项目上添加 github 票证。
或者,使用现有的 IoC 容器代替现有容器。有些人还添加了自定义贡献者来自己进行清理,而无需使用外部容器。
塞布
Disposing is a whole bag of pain to implement right. Per-request objects have a known object lifetime (containers that implement the OR DI interface have a hook to know when to dispose that scope), statics (since 2.1.1) will be disposed by the container on shutdown of the host (which means nearly never for asp.net, and whenever you close the self-hosted server / in mem hosting), and transients we have no clue how to do it: how do you know when something has to be disposed if you don't keep track of it, which if you do means that it doesn't get released, it's all very problematic.
So the internal DI container doesn't dispose anything at all, although we may add the disposing of singletons on container dispose and of per-request on request shutdown, I suppose that'd be quite useful. Feel free to add a github ticket on the openrasta-core project.
Alternatively, use an existing IoC container in place of the existing one. Some people have also added custom contributors to do the cleanup themselves without having to use an external container.
Seb