Prism (CAL) 中的模块如何相互通信?

发布于 2024-07-25 17:15:58 字数 436 浏览 1 评论 0原文

我有一个 WPF 应用程序,它自始至终都使用 MVVM 模式,没有代码隐藏,ViewModel 通过注入到每个 ViewModel 中的 MainViewModel 相互通信。

最终,这个应用程序需要合并到一个使用复合应用程序库、Unity 等的应用程序中。查看 CAL 的代码和文档,我可以看到如何注册我的整个应用程序作为 CAL 应用程序中的模块,但是我的应用程序作为模块将如何与同样动态加载的其他模块进行通信? 我期望,例如每个模块以某种方式注入CAL应用程序,或者有某种事件控制器Messenger我可以与其他模块松散地通信,即可以发送消息并响应事件,但不用担心这些模块是否确实存在。

复合应用程序模块如何相互通信?

I've got a WPF application which uses the MVVM pattern throughout, no code-behind, the ViewModels communicate with each other through the MainViewModel which gets injected into each of them.

Eventually, this application needs to be incorporated into an application which uses Composite Application Library, Unity, etc. Looking through the code and documentation of CAL, I can see how I can register my whole application as a module in the CAL application, but how is my application-as-module going to communicate with the other modules that are also dynamically loaded? I'm expecting, e.g. that each module gets the CAL application somehow injected, or that there is some kind of Event Controller or Messenger with which I can loosely communicate with the other modules, i.e. can send a message and respond to events but not worry if those modules are actually there or not.

How do Composite Application modules communicate with each other?

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

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

发布评论

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

评论(2

猫卆 2024-08-01 17:15:59

如果您使用 CAL(Prism),请查看事件聚合器/CompositePresentationEvent它使用发布者/订阅者模式(又名发布/订阅),因此应用程序的某些模块订阅了事件聚合器,因此当另一个模块发生更改时,它将发布更改,例如(SelectedItemChanged)到事件聚合器,如果其他模块是对已发布的更改感兴趣,他们将在应用程序的该部分中执行操作。

示例:

桌面电子邮件应用程序:

模块:

  • 邮件项目(MailID、主题、发件人、SentDate 等)
  • 详细信息视图(MessageBody)

如果邮件项目列表框中的选择发生更改,则会发布将 MailID 发送到事件聚合器,然后详细信息视图了解更改,然后通过 MailID 获取该电子邮件的 MessageBody。 其中“MailItems”和“DetailView”模块是由不同的团队开发的,但它们之间有 MailID 作为共同的预期消息。

If you are using CAL(Prism) look into the Event Aggregator/CompositePresentationEvent where it uses the Publisher/Subscriber pattern (aka Pub/Sub) so some Modules of the app is subscribed to an Event Aggregator, so when another Module has changes it will Publish changes e.g.(SelectedItemChanged) to the Event Aggregator, If Other Modules are interested in the changes Published they will act within there part of the application.

Example:

A Desktop e-mail Application:

Modules:

  • Mail Items (MailID,Subject,Sender,SentDate..etc)
  • Detail View (MessageBody)

If the selection in the Mail Items ListBox gets changed,It publishes the MailID to the Event Aggregator then Detail View knows about the change and then it grabs the MessageBody for that E-mail by MailID. where "MailItems" and "DetaliView" Modules have been developed by different teams but they have MailID as a common expected message in between.

柒夜笙歌凉 2024-08-01 17:15:59

查看 Prism 的事件聚合器

Check out Prism's event aggregator.

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