简体   繁体   English

IoC和Managed AddIn Framework(System.AddIn)可以与隔离的AppDomain一起工作吗?

[英]Can IoC and the Managed AddIn Framework (System.AddIn) work together with isolated AppDomains?

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? 如果我使用Managed AddIn Framework(System.AddIn)并将其设置为使用单独的AppDomain,我可以使用主/默认AppDomain中的集中式IoC容器吗? Can the IoC container resolve across the AppDomains? IoC容器可以跨AppDomains解析吗?

I'm going to approach this answer by ignoring the MAF part of the equation, and concentrating on the AppDomain issue. 我将通过忽略等式中的MAF部分来解决这个问题,并专注于AppDomain问题。 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. 假设IoC入口点继承自MarshalByRefObject或由一个继承自MarshalByRefObject的类包装,理论上IoC容器可以执行您所描述的操作。 With a 29K+ rep score, I am sure you know this but: 凭借29K +的得分,我相信你知道这一点但是:

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). 1)从MarshalByRefObject继承的对象可以通过代理跨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. 2)可序列化的对象可以通过序列化传递到AppDomain边界,也就是说,您可以在另一个AppDomain中获取它们的另一个副本。

For a number of reasons, you wouldn't want to serialize your whole IoC container and ship it across the AppDomain boundary. 出于多种原因,您不希望序列化整个IoC容器并将其通过AppDomain边界发送。 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. 首先,这样做的开销将是巨大的,其次,IoC容器背后可能存在许多不可序列化的管道。 Therefore the only possible way for this to work is if: 因此,唯一可行的方法是:

1) The IoC container itself was MarshalByRef, or was wrapped by such 1)IoC容器本身是MarshalByRef,或者被这样包裹

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). 2)您从IoC容器中获取的对象都已正确设置以供跨域使用(可序列化或MBR继承)。

If both of the above are true, then you could theoretically use the IoC container hosted in the main AppDomain from other AppDomains. 如果上述两种情况都属实,那么理论上你可以使用其他AppDomain主AppDomain中托管的IoC容器。 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容器的Resolve方法的MAF主机适配器(或您使用的IoC工具中的等效物)来实现此目的。

Keep in mind that a LOT of IoC functionality (especially AOP) is implemented using the same proxy APIs that cross-appdomain communication also uses. 请记住,使用跨应用程序域通信也使用的相同代理API实现了大量IoC功能(尤其是AOP)。 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容器用于基本的可序列化结构和MBR继承服务以外的任何东西,我肯定会看到这种复杂的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM