通过类似服务总线的方式在应用程序内部进行模块通信 [英] Modules communication inside application by something like servicebus

查看:20
本文介绍了通过类似服务总线的方式在应用程序内部进行模块通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要构建一个 destop 应用程序.
操作员处理商店列表.他有一个用于过滤商店的主窗口,并且还有许多额外的窗口:地图(显示商店的位置,在地图上将列表中的选定商店标记为粗体)、库存表格(查询选定商店库存的外部服务).除主窗体外,可同时打开或隐藏部分窗体.

We need to build a destop application.
Operator works with a list of shops. He has a main window where he filters shops and he has a number of extra windows: map(shows location of shops, marks the selected shop from list as bold on map), stock form(queries external service for stock of selected shop). The forms can be opened simultaneously or some of them can be hidden, except main form.

可能的实施:
我认为每个表单都是我的应用程序的独立模块.为什么?我预计表单的数量会增加.例如,商店最新销售的新表格,与商店经理聊天的另一种表格.

Possible Implementation:
I consider each form as standalone module of my application. Why? I expect that number of forms will grow. For example, new form for latest sales in shop, another form for a chat with shop manager.

问题:
如何组织模块之间的通信?
现在我有一个使用共享总线的想法,模块可以通过它发送和接收消息.
有没有其他选择?
是否有此总线的任何实现,或者我已经足够基于发布者/订阅者模式的直接实现?

Questions:
How do I organize communications between modules?
For now I have an idea to use a shared bus and modules can send and receive messages throught it.
Are there any alternatives?
Are there any implementation of this bus or I'm enough with straight forward implementation build upon publisher/subscriber pattern?

推荐答案

首先,您需要保持模块解耦.否则,这将导致模块之间的依赖关系非常糟糕.
为了实现这一点,最好的方法是使用 EventAggregator 结构.虽然名字看起来是事件,但实际上它是一个管理发布/订阅的总线结构.

First, you need to keep the modules decoupled. Otherwise, it will result with a hell of dependencies between modules.
To achieve this, best offer is using an EventAggregator structure. Though the name seems as event, in fact, it's a bus structure to manage pub/sub.

您可以在此处找到有关 EventAggregator 模式的信息.

You can find information about EventAggregator pattern form here.

.NET 世界有一个开源 API(名为 Prism)提供这种能力.我强烈建议您从 这里 并挖掘源代码.

.NET world have an opensource API (named Prism) providing this capability. I strongly suggest you to read the Event Aggregation section of Prism documentation from here and digg the source code.

目前我们正在开发一个 Silverlight 应用程序,该应用程序包含彼此完全解耦的不同模块(没有模块知道另一个模块的实例/引用)并通过 Prism API 进行通信.

Currently we are developing a Silverlight application which is including different modules totally decoupled from each other (no module knows instance/reference of the other one) and communicating via Prism API.

这篇关于通过类似服务总线的方式在应用程序内部进行模块通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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