使用 Prism 跨模块通信? [英] Communicating across modules with Prism?

查看:41
本文介绍了使用 Prism 跨模块通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 Prism 文档,它说有四种跨模块通信的方式 -

From following the Prism documentation it says there are four ways to communicate across modules -

  • 解决方案指挥
  • 区域背景
  • 共享服务
  • 事件聚合

  • Solution commanding
  • Region context
  • Shared services
  • Event aggregation

  1. 我可以只选择其中一种方法并将其应用于所有跨模块通信吗?还是应该根据情况使用不同的方法?
  2. 特别是,在我编写的应用程序中,我在一个模块中有按钮,当用户单击它时,我想在另一个模块中启动一个线程.在这种情况下,我会使用哪种沟通方式?

推荐答案

Ans 1:是的,您可以全面使用单一方法.大多数情况下,这样做会更容易.

Ans 1: Yes, you can use a single approach all-over. Most of the times it will be easier to do it that way.

Ans 2:我建议您使用事件聚合来做到这一点.这样,按钮单击和线程执行之间的耦合非常松散.这样,监听模块只需要知道一个事件,无论它是从哪里引发的.

Ans 2: I recommend you use Event Aggregation to do that. That way, you have a very loose coupling between the button click and the thread execution. That way, the listening module just has to be aware of a single event no matter where it was raised from.

因为它是一个通知而不是一堆相互关联的通知/通信,所以最好聚合一个事件而不是创建共享服务.

Since, it is a single notification and not a bunch of inter-related notifications/communications, it is better to Aggregate an event rather than creating a Shared Service.

这篇关于使用 Prism 跨模块通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆