StructureMap ReleaseAndDisposeAllHttpScopedObjects 不会导致 Dispose 调用
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我的菜鸟!在依赖关系图的较高位置有一个对象配置为单例范围,因此挂在我想要在每个请求结束时处理的对象(连接提供程序)上!将该对象的范围从 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!