温莎注册子容器可见性
我有一些(某种)单例存在于三个上下文中:
Per AppDomain
Per HttpApplication
Per Web Request
Right现在,我正在为每个 HttpApplication 创建一个子容器,并为每个 Web 请求创建另一个子容器。这是必要的,因为某些组件实际上应该跨三层共享单例实例。出于安全和其他原因,某些注册实际上不应共享单例(每个容器一个)。
有人对如何实现这一点或者如何限制容器层次结构中注册的可见性有建议吗?
谢谢。
I have some (sort of) Singletons which exist in three context:
Per AppDomain
Per HttpApplication
Per Web Request
Right now, I'm creating a child container per HttpApplication and another child per Web Request. This is necessary because some components SHOULD actually share singleton instances across the three layers. For security and other reasons, there are certain registrations that SHOULD NOT actually share the singleton (one per container).
Does anyone have a suggestion as to how to implement this or how I can limit the visibility of registrations within a container hierarchy?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如斯图尔特所说,生活方式是做到这一点的正确延伸点。子容器不是必需的。在 Windsor 中,每个 Web 请求都是开箱即用的,IIRC 单例生活方式(默认生活方式)适用于每个应用程序域。每个 HttpApplication 的生活方式是在 Castle.Windsor.Lifestyles contrib 项目 中实现的。
As Stuart says, lifestyles are the correct extension point to do this. Child containers are not necessary. Per web request comes out of the box in Windsor, and IIRC the Singleton lifestyle (the default one) works per appdomain. The per-HttpApplication lifestyle is implemented in the Castle.Windsor.Lifestyles contrib project.
您是否尝试过使用 lifestyles 来解决这个问题? Singleton 和 PerWebRequest 生活方式的组合可以满足您的要求,而不需要子容器。
Have you tried using lifestyles to solve this problem? A combination of the Singleton and PerWebRequest lifestyles may satisfy your requirements, without requiring child containers.