在两个远程对象之间设置双向通信线路时的循环引用

发布于 2024-09-03 11:05:54 字数 596 浏览 4 评论 0原文

我正在使用 .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 gets StaticObjectA gets RemoteObjectB gets StaticObjectB gets RemoteObjectA... 中的循环引用...

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

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

I'm using .Net remoting to set up a bidirectional communication line between two objects. The basic structure is as follows:

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.

The problem with this setup is the circular reference in RemoteObjectA gets StaticObjectA gets RemoteObjectB gets StaticObjectB gets RemoteObjectA...

I implemented an interface IRemoteObjectA and IRemoteObjectB and had the remote objects inheret from their respective interfaces, but then setting up the remoting fails.

If the solution to this problem is: "don't use remoting", I can deal with that. Just wanted to make sure I wasn't missing a simple solution.

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

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

发布评论

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

评论(1

我不吻晚风 2024-09-10 11:05:54

想通了。

诀窍是为静态对象创建一个接口。因此 StaticObjectA 和 RemoteObjectA 都获取 IStaticObjectA,StaticObjectB 和 RemoteObjectB 都获取 IStaticObjectB。这样StaticObjectA可以获取RemoteObjectB,StaticObjectB也可以获取RemoteObjectA,而不会出现循环依赖。

Figured it out.

The trick was to create an interface for the static objects. So StaticObjectA and RemoteObjectA both get IStaticObjectA and StaticObjectB and RemoteObjectB both get IStaticObjectB. This way StaticObjectA can get RemoteObjectB and StaticObjectB can get RemoteObjectA with no circular dependency.

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