CompositeWPF:EventAggregator - 何时使用?
我一直在研究复合应用程序库,它很棒,但我无法决定何时使用 EventAggregator...或者更确切地说 - 何时不使用它。
看看 StockTraderRI 的例子,我更加困惑了。 他们在某些情况下使用 EventAggregator,在其他情况下使用“经典”事件(例如在 IAccountPositionService 接口中)。
我已经决定使用它来与繁重的工作任务进行通信,该任务应该在后台线程上运行。 在本例中,EventAggregator 在幕后提供线程编组,因此我不必对此太担心。 除此之外,我喜欢这种方法提供的解耦。
所以我的问题是:当我开始在应用程序中使用 EventAggregator 时,为什么不将其用于所有自定义事件?
I've been looking in to the Composite Application Library, and it's great, but I'm having trouble deciding when to use the EventAggregator... or rather - when NOT to use it.
Looking at the StockTraderRI example, I'm even more confused. They are using the EventAggregator in some cases, and "classic" events in other cases (in for example the IAccountPositionService interface).
I've already decided to use it for communication with a heavy work task, that should run on a background thread. In this case the EventAggregator offers marshalling of threads behind the scenes, so I don't have to worry much about that. Besides that I like the decoupling this approach offers.
So my question is: When I've started using the EventAggregator in my application, why not use it for all custom events?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个很好的问题。 在 Composite WPF (Prism) 中,有 3 种可能的方式在应用程序的各个部分之间进行通信。 一种方法是使用 Commanding,它仅用于将 UI 触发的操作传递到实现该操作的实际代码。 另一种方法是使用共享服务,其中多个部分保存对同一服务(单例)的引用,并以经典方式处理该服务上的各种事件。 对于断开连接和异步通信,正如您已经说过的,最好的方法是使用事件聚合器(它严格遵循 Martin Fowler 的模式)。
现在,何时使用和不使用它:
我希望这回答了你的问题。
This is a good question. In Composite WPF (Prism) there are 3 possible ways to communicate between parts of your app. One way is to use Commanding, which is used only to pass UI-triggered actions down the road to the actual code implementing that action. Another way is to use Shared Services, where multiple parts hold a reference to the same Service (Singleton) and they handle various events on that service in the classical way. For disconnected and asynchronous communication, as you already stated, the best way is to use the Event Aggregator (which follows closely Martin Fowler's pattern).
Now, when to and not to use it:
I hope this answers your question.