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

守給你的承諾、 提交于 2019-12-04 12:13:09

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!