IoC 和托管外接程序框架 (System.AddIn) 能否与隔离的 AppDomain 一起工作?

发布于 2024-10-19 08:26:46 字数 120 浏览 2 评论 0原文

如果我使用托管 AddIn 框架 (System.AddIn) 并将其设置为使用单独的 AppDomain,我可以使用主/默认 AppDomain 中的集中式 IoC 容器吗? IoC 容器可以跨 AppDomain 解析吗?

If I use Managed AddIn Framework (System.AddIn) and set it up to use separate AppDomains, can I use a centralized IoC container that is in the primary/default AppDomain? Can the IoC container resolve across the AppDomains?

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

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

发布评论

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

评论(1

维持三分热 2024-10-26 08:26:46

我将通过忽略等式的 MAF 部分并专注于 AppDomain 问题来接近这个答案。理论上,IoC 容器可以执行您所描述的操作,假设 IoC 入口点继承自 MarshalByRefObject 或由一个继承自 MarshalByRefObject 的类包装。凭借 29K+ 的代表分数,我相信您知道这一点,但是:

1)从 MarshalByRefObject 继承的对象可以通过代理跨 AppDomain 边界访问(也就是说,所有调用都跨 AppDomain 边界编组到对象)。

2)可序列化的对象可以通过序列化跨AppDomain边界传递,也就是说,您可以在另一个AppDomain中获得它们的另一个副本。

由于多种原因,您不希望序列化整个 IoC 容器并将其运送到 AppDomain 边界。首先,这样做的开销将是巨大的,其次,IoC 容器背后可能存在大量不可序列化的管道。因此,唯一可能的方法是,如果:

1)IoC 容器本身是 MarshalByRef,或者被此类容器包装

,并且

2)您从 IoC 容器获取的对象都已正确设置为跨域使用(可序列化或 MBR 继承)。

如果上述两个条件都成立,那么理论上您可以从其他 AppDomain 使用主 AppDomain 中托管的 IoC 容器。您可能会通过定义特定于 IoC 容器的 Resolve 方法(或您使用的 IoC 工具中的任何等效方法)的 MAF 主机适配器来实现此目的。

请记住,许多 IoC 功能(尤其是 AOP)是使用跨应用程序域通信也使用的相同代理 API 来实现的。如果您尝试将 IoC 容器用于除基本可序列化结构和 MBR 继承服务之外的其他用途,我肯定会看到事情变得复杂。

I'm going to approach this answer by ignoring the MAF part of the equation, and concentrating on the AppDomain issue. An IoC container could theoretically do what you describe, assuming that the IoC entry point inherits from MarshalByRefObject or is wrapped by a class that in turn inherits from MarshalByRefObject. With a 29K+ rep score, I am sure you know this but:

1) Objects which inherit from MarshalByRefObject can be accessed across AppDomain boundaries via proxying (that is, all of the calls are marshalled across the appdomain boundary to the object).

2) Objects that are serializable can be passed across the AppDomain boundary via serialization, that is, you can get another copy of them in the other AppDomain.

For a number of reasons, you wouldn't want to serialize your whole IoC container and ship it across the AppDomain boundary. First off, the overhead of doing that would be enormous, and secondly there is likely a lot of plumbing behind an IoC container that isn't serializable. Therefore the only possible way for this to work is if:

1) The IoC container itself was MarshalByRef, or was wrapped by such

and

2) The objects that you were getting from the IoC container were all set up properly for cross-domain use (either serializable or MBR-inheriting).

If both of the above are true, then you could theoretically use the IoC container hosted in the main AppDomain from other AppDomains. You'd probably do this by defining a MAF host adapter that was specific to the IoC container's Resolve methods (or whatever the equivalent is in the IoC tool you use).

Keep in mind that a LOT of IoC functionality (especially AOP) is implemented using the same proxy APIs that cross-appdomain communication also uses. I could definitely see this complicating things if you attempt to use the IoC container for anything more than basic serializable structures and MBR-inheriting services.

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