Prism:寻找如何设计不一定符合标准区域布局的应用程序的想法
我有一个应用程序,其中有几个具有完全不同功能的模块,我正在尝试找出使用 prism 实现此功能的最佳方法。
为了更好地解释,我将尝试使用 Northwind 为例。我有 3 个模块:订单、客户和订单。雇员。
客户模块将允许您执行与客户相关的任何操作。添加、删除和编辑。我将使用客户模块中主视图的范围区域来处理我需要在此处显示的所有不同视图。
在上面的场景中,我只想在用户想要与客户、订单或员工合作时加载模块。
您布置了这些模块,并意识到您需要能够向显然是员工的客户或销售人员显示订单。
在这种情况下,您会做什么,因为您不想为雇员订单和客户订单创建全新的模块,并且您不想复制任何订单相关的代码。
我开始怀疑,如果您正在构建 Outlook 这样的应用程序,那么考虑使用 Prism 构建复合应用程序是否可行,但对于 LOB 业务应用程序,我还没有找到如何执行此操作的良好示例,并且为此,不要违反 MVVM 的一些原则和 Prism 的定义。
我刚使用 Prism 3 周,仍在学习,但这是我遇到的最大问题。
有什么想法吗?
I have an app that has several modules that have completely different functionality and I'm trying to figure out the best way to implement this using prism.
To try and better explain, I'll try to use Northwind as an example. I have 3 modules, orders, customers & employees.
The customer module will allow you to do anything pertaining to a customer. Add, remove and edit. I'm going to use scope regions for the main view in the customer module to handle all the different views I need to show here.
In the scenario above, I only want to load a module when a user wants to work with say a customer, order or employee.
You have these modules laid out and realize that you need to be able to show Orders for customer or sales people which are obviously employees.
What would you do here in this scenario as you wouldn't want to create an entirely new modules for say employeeOrders and customerOrders and you wouldn't want to duplicate any order related code.
I'm starting to wonder if it's feasible to think about building a composite application using prism if you're building an app like Outlook, but for a LOB business app, I've yet to find a good sample of how to do this and not break some of the principles of MVVM and definitions of Prism in order to do so.
I'm just 3 weeks into Prism and still learning but this is the biggest issue I'm running into.
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于这些类型的通信场景,您应该使用事件聚合器。本质上,您希望模块提供功能,但也公开可以从其他模块调用的事件。您还可以在 Unity 容器中注册服务。例如:
这些技术在某种程度上与 MVVM 正交。您的事件处理程序可以创建视图/视图模型对并将它们插入到区域中。或者,您的事件处理程序可以创建一个 UserControl,其所有功能都在后面的代码中实现,并将其添加到一个区域。复合 UI 的美妙之处在于,您的模块可以使用 MVVM,而另一个团队的模块可以使用直接的用户控件、MVP 或 MVC 或任何其他东西;关键是所有模块都被组合成一个应用程序,无论它们如何实现,因为它们使用 Prism 中建立的模式,如区域、事件等。
在您的特定情况下:
您的订单模块肯定会知道客户 ID 的概念,因为订单实体与客户相关联。 Order 模块应该公开一个 CompositePresentationEvent,该事件显示一个包含特定客户 ID 的所有订单的视图。
Prism 的重点是创建逻辑上独立且松散耦合的功能块。这并不意味着模块之间不进行通信,而是通信以有限且松散耦合的方式进行。您当然可以使用此模式和 MVVM 编写 LOB 应用程序;我们中的许多人已经这样做很多年了。 :)
You should be using the Event Aggregator for these types of communication scenarios. Essentially, you want a module to provide functionality but also expose events that can be invoked from other modules. You can also register a service in the Unity container. For example:
These techniques are somewhat orthogonal to MVVM. Your event handler can create a view/viewmodel pair and insert them into a region. Or your event handler can create a UserControl with all functionality implemented in code behind and adds it to a region. The beauty of the composite UI is that your modules can use MVVM and another team's modules can use straight forward user controls or MVP or MVC or anything really; the point is that all the modules are composed into one application regardless of how they are implemented because they use the patterns established in Prism like regions, events, etc.
In your particular case:
Your Order module will certainly be aware of the concept of a customer id since the Order entity is associated with a customer. The Order module should expose an CompositePresentationEvent that displays a view that has all the orders for a particular customer id.
The point of Prism is to create logically separate and loosely coupled pieces of functionality. This does not mean that the modules do not communicate with each other, but rather that the communication happens in a limited and loosely coupled manner. You can certainly write LOB applications using this pattern and MVVM; many of us have been for years now. :)
我正在研究类似的问题(而且我也是 Prism 新手),但目前还没有解决方案。我认为在使用 Prism 时,很容易将框架用作参考实现的意图,但事实并非如此。
Prism 应该(如果使用正确)促进软件开发,而不是阻碍它。因此,不要太执着于任何实现都必须满足严格的解耦重构超级模式化标准的想法!
我正在做/打算做的是创建一个 MainModule,其中包含我的许多核心功能,包括 MainView/MainViewModel 用户控件。然后,Shell 有一个区域“Main”,并且在 MainModule 加载时,MainView 将按照标准棱镜用法注入其中。
我在 MainView 上使用来自 Telerik 的 Docking Manager(与 Silverlight 和 WPF 兼容),并在基础设施中实现了类 IDockingManager / DockingManager 类,该类在 Unity 中注册为引导程序中的单例 (ContainerControlledLifetimeManager)。
在我的应用程序中的任何位置,我都可以获取 IDockingManager 实例并通过调用 IDockingManager.DockView(IView view, DockingParameters args) 注入视图。 DockingParameters 可以包含诸如停靠位置(左、右、上、下、选项卡式文档)以及要停靠的父容器等信息。
这是我还没有完成的部分 - 我可以停靠左/右/主视图上的顶部/底部,但我想在我的子视图上实现附加属性或某些内容,在停靠时将它们注册为 DockSite。例如,我可以将 Treeview 停靠在左侧,并将 Treeview 停靠在列表视图下方,方法是使用 Treeview 名称作为父 DockSite,使用 DockBottom 作为侧面。
希望这是有道理的,我已经胡言乱语了,没有真正解释得很好。基本上我想说的是,我在这个应用程序中根本不使用区域(除了注入 MainView),并且创建了一个类来处理可停靠容器中的视图注入。严格来说,它不是 Prism,但 Prism 的存在是为了让我的生活更轻松,而不是相反;)
Im working on a similar problem (and am new to Prism too), as yet don't have a solution. I think when using Prism its tempting to use the framework as the reference implementation intends, but it doesn't need to be so.
Prism should (when used correctly) facilitate software development, not hinder it. So don't get too stuck in the idea that any implementation must meet strict decoupled refactorised super patternised standards!
What I am doing/intending to do is create a MainModule, which has in it much of my core functionality, including a MainView/MainViewModel user control. The Shell then has one region "Main" and on MainModule load the MainView is injected into it as per standard prism usage.
I'm using a Docking Manager from Telerik (compatible with Silverlight and WPF) on the MainView and have implemented a class IDockingManager / DockingManager class in Infrastructure which is registered with Unity as a singleton (ContainerControlledLifetimeManager) in the bootstrapper.
Anywhere in my app I can get the IDockingManager instance and inject a view by calling IDockingManager.DockView(IView view, DockingParameters args). The DockingParameters can contain information such as where to dock (Left, right, top, bottom, tabbed document) and also the parent container to dock in.
This is the part I've not got to yet - I can dock left/right/top/bottom on the main view but I want to implement an attached property or something on my child views registering them as a DockSite when docked. So for instance I could dock a Treeview on the left and dock underneath that a listview by using the Treeview name as parent DockSite and DockBottom as the side.
Hope that makes sense, I've rambled without really explaining too well. Basically what Im saying is Im not using regions at all (except to inject the MainView) in this application and have created a class to handle view injection into dockable containers. It's not strictly Prism but Prism is there to make my life easier, not the other way around ;)