AppDomain 之间的通信

发布于 2024-12-28 06:33:53 字数 789 浏览 1 评论 0原文

我们正在构建一个应用程序(WinForms,.NET 3.5),它将“插件”DLL 加载到辅助应用程序域中。辅助 AppDomain 偶尔需要与第一个 AppDomain 进行通信(更具体地说,从主 AppDomain 中创建的对象调用或获取数据)。

我已经阅读了大部分有关 AppDomains 以及它们之间的通信的材料。

到目前为止,我见过的唯一简单的解决方案是继承 MarshalByRefObject 并将 TransparentProxy 传递到第二个AppDomain,调用Proxy上的方法。

此方法有其缺点(例如,在框架类型或已经从另一个类、静态字段/类等继承的类型的情况下,并不总是可以从 MBRO 继承)。

由于当前的通信点相当恒定(只有 2-3 个场景需要通信),我考虑创建一个简单的 Mediator 类,具有以下属性:

  1. 将在第一个(主)应用程序域。
  2. 仅充当主应用程序域中创建的“真实”对象的“消息传递者”。
  3. 将从MBRO继承,并且对其的代理引用将被发送到第二个AppDomain。

将调用该代理对象上的方法,该代理对象又将调用第一个 AppDomain 中“真实”对象上的方法。

我的问题——

  1. 这看起来是一个合乎逻辑的设计吗?
  2. 更重要的是,WCF 或任何其他通信框架中是否已经存在中介/消息传递器类?这似乎是一个通用概念,我想知道是否有类似的东西。

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:

  1. Will be created in the 1st (Main) AppDomain.
  2. Would function only as a "message-passer" to the "Real" objects that are created in the main AppDomain.
  3. 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 --

  1. Does this seem like a logical design?
  2. 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.

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

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

发布评论

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

评论(1

平定天下 2025-01-04 06:33:53

除非您出于某种原因特别想避免使用 WCF,否则我建议您看一下它。具体来说,您可以使用 NetNamedPipeBinding,它提供使用命名管道在同一台计算机上进行通信。您可以在这里找到更多信息:
http://msdn.microsoft.com/en-us/library /system.servicemodel.netnamedpipebinding.aspx

另外,这里是一个相当简洁的博客条目演示其使用(从 WMP 插件到第三个插件) -派对应用程序)。

根据您对应用程序的描述,您可以在第一个 AppDomain 中建立 WCF 服务,然后从第二个 AppDomain 调用该服务。

Unless you specifically want to avoid WCF for some reason, I would suggest taking a look at it. Specifically, you can use the NetNamedPipeBinding, which provides for communication on the same machine using named pipes. You can find some more information here:
http://msdn.microsoft.com/en-us/library/system.servicemodel.netnamedpipebinding.aspx

As well, here is a reasonably concise blog entry demonstrating it's use (from a WMP plug-in to a third-party app).

Based on your description of the application, you could establish a WCF service in the first AppDomain then call into that service from the second AppDomain.

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