IoC和托管加载项框架(System.AddIn)可以与隔离的AppDomain一起使用吗? [英] Can IoC and the Managed AddIn Framework (System.AddIn) work together with isolated AppDomains?

查看:100
本文介绍了IoC和托管加载项框架(System.AddIn)可以与隔离的AppDomain一起使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用托管加载项框架(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?

推荐答案

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

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)可以从MarshalByRefObject继承的对象通过代理访问AppDomain边界(即

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)可序列化的对象可以通过序列化跨AppDomain边界传递,也就是说,您可以获得

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.

由于许多原因,您不希望序列化整个IoC容器并将其跨AppDomain边界运送。首先,这样做的开销非常大,其次,不可序列化的IoC容器背后可能有很多麻烦。因此,唯一可行的方法是:

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)IoC容器本身是MarshalByRef,或由此类容器包装

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

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

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).

如果以上两个条件都成立,那么理论上您可以使用其他AppDomain中的主AppDomain中托管的IoC容器。您可能会通过定义特定于IoC容器的Resolve方法(或所使用的IoC工具中的等效项)的MAF主机适配器来做到这一点。

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).

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

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.

这篇关于IoC和托管加载项框架(System.AddIn)可以与隔离的AppDomain一起使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆