统一使用 IObservable

发布于 2024-09-12 16:57:45 字数 104 浏览 3 评论 0原文

我想使用 iobservable 模式来公开事件流。问题是我使用 unity 来创建观察者和事件生成器。我宁愿不必在应用程序启动时更新这两个内容,这样我就可以开始侦听事件。有人对此有什么建议吗?

I want to use the iobservable pattern to expose a stream of events. The problem is that I'm using unity to create both the observer and the event generator. I would rather not have to new up both of these at application start just so I can start listening for events. Does any one have any suggestions about this?

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

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

发布评论

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

评论(1

醉城メ夜风 2024-09-19 16:57:45

阅读您对我的评论的回复后(很抱歉延迟,请参阅我的评论)我可以想到两种解决方法。

首先,让订阅者订阅一个包装(即订阅)尚未创建的 IObservable 源的 IObservable。这样,订阅者可以立即订阅,但在创建源之前,值不会开始传递。

另一种选择是创建随 棱镜(2.2,我还没有检查过4)。 EventAggregator 充当广播事件系统,任何代码都可以请求一个可以订阅或发布的Event。在您的情况下,该事件将实现 ISubject (即 IObservableIObserver)。

After reading your reply to my comment (sorry about the delay, see my comment) I can think of two ways of solving it.

Firstly, have the subscriber subscriber to an IObservable that wraps (ie. subscribes to) the yet-to-be-created IObservable source. This way, the subscriber can subscribe immediately, but the values won't start coming through until the source has been created.

The other choice is to create an IObservable flavoured version of the EventAggregator that ships with Prism (2.2, I haven't checked out 4). The EventAggregator acts as a broadcast event system, whereby any piece of code can ask for an Event which can be either subscribed to or published to. In your case, the event would implement ISubject (that is, both IObservable and IObserver).

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