温莎注册子容器可见性

发布于 2024-09-28 19:33:04 字数 323 浏览 0 评论 0原文

我有一些(某种)单例存在于三个上下文中:

  1. Per AppDomain

  2. Per HttpApplication

  3. Per Web Request

Right现在,我正在为每个 HttpApplication 创建一个子容器,并为每个 Web 请求创建另一个子容器。这是必要的,因为某些组件实际上应该跨三层共享单例实例。出于安全和其他原因,某些注册实际上不应共享单例(每个容器一个)。

有人对如何实现这一点或者如何限制容器层次结构中注册的可见性有建议吗?

谢谢。

I have some (sort of) Singletons which exist in three context:

  1. Per AppDomain

  2. Per HttpApplication

  3. 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 技术交流群。

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

发布评论

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

评论(2

眼眸 2024-10-05 19:33:04

正如斯图尔特所说,生活方式是做到这一点的正确延伸点。子容器不是必需的。在 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.

残疾 2024-10-05 19:33:04

您是否尝试过使用 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.

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