【问题标题】:Circular reference while setting up bidirectional communication line between two remote objects在两个远程对象之间建立双向通信线路时的循环引用
【发布时间】:2010-05-24 19:55:37
【问题描述】:

我正在使用 .Net 远程处理在两个对象之间建立双向通信线路。基本结构如下:

Instances of RemoteObjectA call methods on StaticObjectA.
Instances of RemoteObjectB call methods on StaticObjectB.
StaticObjectA needs to be able to call methods provided by RemoteObjectB.
StaticObjectB needs to be able to call methods provided by RemoteObjectA.

这个设置的问题是RemoteObjectA中的循环引用得到StaticObjectA得到RemoteObjectB得到StaticObjectB得到RemoteObjectA...

我实现了一个接口 IRemoteObjectA 和 IRemoteObjectB 并从它们各自的接口中继承了远程对象,但是设置远程处理失败。

如果这个问题的解决方案是:“不要使用远程处理”,我可以处理。只是想确保我没有错过一个简单的解决方案。

【问题讨论】:

    标签: c# remoting circular-dependency


    【解决方案1】:

    想通了。

    诀窍是为静态对象创建一个接口。所以 StaticObjectA 和 RemoteObjectA 都得到 IStaticObjectA 和 StaticObjectB 和 RemoteObjectB 都得到 IStaticObjectB。这样StaticObjectA可以得到RemoteObjectB,StaticObjectB可以得到RemoteObjectA,没有循环依赖。

    【讨论】:

      猜你喜欢
      • 2020-05-25
      • 2019-05-19
      • 1970-01-01
      • 1970-01-01
      • 2013-12-04
      • 1970-01-01
      • 1970-01-01
      • 2011-10-18
      相关资源
      最近更新 更多