StructureMap ReleaseAndDisposeAllHttpScopedObjects 不会导致 Dispose 调用

发布于 2024-12-12 08:05:30 字数 482 浏览 0 评论 0原文

我在 Application_EndRequest 中调用 ObjectFactory.ReleaseAndDisposeAllHttpScopedObjects() ,它按预期触发,但是它不会导致容器内的任何 Http-Scoped 实例被处理。如果我在 Application_EndRequest 中调用 WhatDoIHave,我可以看到我想要调用 Dispose 的 Http 范围实例,但它不会发生!有什么想法为什么不呢?

当我查看 HttpContext.Current.Items StructureMap 时,其中没有隐藏任何内容,我猜它应该有?注册为请求范围的项目示例如下:

For<IConnectionProvider>().HybridHttpOrThreadLocalScoped().Use<ConnectionProvider>();

IConnectionProvider 继承自 IDisposable。

I am calling ObjectFactory.ReleaseAndDisposeAllHttpScopedObjects() in Application_EndRequest which is firing as expected, however it is not causing any Http-Scoped instances inside the container from being Dispose'd of. If I call WhatDoIHave in Application_EndRequest, I can see the Http-Scoped instances that I want to have Dispose called on, but it doesn't happen! Any ideas why not?

When I look in HttpContext.Current.Items StructureMap hasn't stashed anything in there and I'm guessing it should have? An example of an item registered to be request scoped is as follows:

For<IConnectionProvider>().HybridHttpOrThreadLocalScoped().Use<ConnectionProvider>();

IConnectionProvider inherits from IDisposable.

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

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

发布评论

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

评论(1

冰魂雪魄 2024-12-19 08:05:30

这是我的菜鸟!在依赖关系图的较高位置有一个对象配置为单例范围,因此挂在我想要在每个请求结束时处理的对象(连接提供程序)上!将该对象的范围从 Singleton 更改为 Transient 导致一切都开始按照我想要的方式工作!

This was my noob! Had an object higher up the dependency graph configured as Singleton scoped, thus hanging onto the object (connection provider) that I wanted to be disposed of at the end of each request! Changing the scoping of this object from Singleton to Transient caused everything to start working as I wanted it to!

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