在两个远程对象之间设置双向通信线路时的循环引用
我正在使用 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
想通了。
诀窍是为静态对象创建一个接口。因此 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.