我有一个 WPF 应用程序,我在其中使用了 MVVM 模式.
I have a WPF application where I'm using the MVVM pattern.
我为需要用户输入的操作激活了 VM,因此需要从 VM 激活视图.
I get the VM activated for actions that require user input and thus need to activate views from the VM.
我开始将 VM 分成单独的组件/程序集,部分原因是我将它们视为单元可测试部分,部分原因是视图应该依赖于 VM,而不是相反.但是当我需要打开一个窗口时,VM 不知道该窗口.
I've started out separating the VMs into a separate component/assembly, partly because I see them as the unit testable part, partly because views should rely on VM, not the other way round. But when I then need to bring up a window, the window is not known by the VM.
我发现的所有介绍都将 VM 放在 WPF/App 组件中,从而消除了问题.
All introductions I find place the VM in the WPF/App component, thus eliminating the problem.
本文建议将它们放在单独的层中:waf.codeplex/wikipage?title=Architecture%20-%20Get%20The%20Big%20Picture&referringTitle=Home
This article recommends keeping them in separate layers : waf.codeplex/wikipage?title=Architecture%20-%20Get%20The%20Big%20Picture&referringTitle=Home
据我所知,我有以下选择
As I see it, I have the following choices
将虚拟机移动到 WPF/App 程序集以允许虚拟机直接访问窗口.
Move VMs to the WPF/App assembly to allow VMs to access the windows directly.
将视图的接口放在VM-assembly中,在WPF/App assembly中实现视图,并通过IOC或其他方式注册连接.
Place interfaces of views in VM-assembly, implement views in WPF/App assembly and register the connection through IOC or alternative ways.
将来自 VM 的请求"提交到路由请求的某种机制/总线(但哪种机制!?例如 Prism 中的某些东西?!)
File a 'request' from the VM into some mechanism/bus that routes the request (but which mechanism!? E.g something in Prism?!)
有什么建议?
感谢您的任何评论,
丹麦安德斯
推荐答案不要选择选项 1.您将添加一个不需要的从 VM 到 V 的依赖项.
Don't pick option 1. You'll be adding an unwanted dependency from VM to V.
选项 2 和 3 都有效并且正在使用.在这些之间进行选择有时是一个品味问题.我认为 IOC 启用/允许模拟更好,而消息总线适用于小型应用程序.
Options 2 and 3 are both valid and being used. Picking between these is sometimes a matter of taste. I think that IOC enables/allows mocking better whereas a messagebus works fine for small applications.
更多推荐
WPF/MVVM
发布评论