We are building an app (WinForms, .NET 3.5) that loads "Plugin" DLLs into a secondary AppDomain. The secondary AppDomain needs to communicate occasionally with the 1st one (more specifically, call or get data from objects that are created in the main AppDomain).
I have read most of the material about AppDomains and communication between them.
So far, the only easy solution i've seen was inheriting from MarshalByRefObject and passing a TransparentProxy into the 2nd AppDomain, calling methods on the Proxy.
This method has its drawbacks (not always possible to inherit from MBRO in case of framework types for example, or types that already inherit from another class, static fields/classes and so on).
Since the current communication points are pretty constant (only 2-3 scenarios that require communication), i have considered creating a simple Mediator class with the following properties:
- Will be created in the 1st (Main) AppDomain.
- Would function only as a "message-passer" to the "Real" objects that are created in the main AppDomain.
- Will inherit from MBRO, and a proxy reference to it will be sent to the 2nd AppDomain.
Methods on this proxy object would be called, which in turn will call the methods on the "real" objects in the 1st AppDomain.
My questions —
- Does this seem like a logical design?
- More importantly, does a mediator/message passer class already exist in WCF or any other communcation framework? it seems like a generic concept and i am wondering if there is something similar.