组件之间的通信(软件设计问题)
我有一个具有以下 UI 组件的应用程序:
- 主菜单
- 文件夹 树形
- 查询生成器
- 选项卡式列表(每个选项卡都有一个可以显示数据实体的网格)
该应用程序基于 MVC,因此上面列出的每个组件都有一个控制器和一个视图。
前三个组件需要在列表上显示数据实体(作为新选项卡):
- 双击文件夹将在新列表中显示该文件夹的项目。
- 单击查询生成器中的搜索按钮时,它将在新选项卡中打开搜索结果。
- 单击“打开...”菜单项并选择文件时,它将打开一个包含文件中项目的新选项卡。
由于可能有很多项目,因此从数据库加载它们的过程是由网格异步完成的(当您查看网格时,网格正在被填充)。
我的问题是:以下哪项是“更干净”的设计? (如果您有更好的解决方案,我将非常感激)
我的第一个解决方案是使用 EventAggregator,定义一个“ShowQuery”事件,让lists控制器订阅它,其他控制器想要显示查询结果时就会发布它。
另一个解决方案类似于 Unity 容器,从其他控制器解析“IListsController”接口,并调用“ShowQuery”方法。
I have an application with the following UI components:
- Main Menu
- Folders Tree
- Query Builder
- Tabbed Lists (each tab has a grid that can display data entities)
The application is based on MVC, so each component listed above has a controller and a view.
The first three components need to display data entities on the list (as new tabs):
- Double clicking on a folder will display the folder's items in a new list.
- When clicking the search button in the query builder it will open the search results in a new tab.
- When clicking "Open..." menu item it and selecting a file it will open a new tab with the items in the file.
Since there could be a lot of items the process of loading them from the database is done asynchronously by the grid (the grid is being filled as you are looking at it).
My question is this: which of the following is a "cleaner" design? (if you have better solutions, I will appreciate it very much)
The first solution I have is to use an EventAggregator, define a "ShowQuery" event, make the lists controller subscribe to it, and the other controllers will publish it when they want to display the query results.
The other solution is something like the Unity Container, and from the other controllers resolve the "IListsController" interface, and call the "ShowQuery" method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论