问题描述
在传统的MDI应用程序中,当发生命令(例如,按下功能区按钮)时,将创建一些对象(窗体),因此它可能是一个合成点。我对此类应用程序中的合成根感到困惑。我读过某个地方,我们可以使用 ViewModelLocator ,它类似于 Service Locator 模式。如您所知,某些人谴责了服务定位器模式。
In traditional MDI applications some objects (Forms) will be created when a command occurs (Ex. pressing a ribbon button), so it maybe a composition point. I'm confiused about composition root in such applications. I read somewhere that we can use a ViewModelLocator which looks like Service Locator pattern. As you know the service locator pattern is denounced by some people.
现在,请就此问题向我提出建议。
Now please advice me about this issue.
谢谢。
推荐答案
ViewModelLocator是否为服务定位器和。
Whether or not a ViewModelLocator is a Service Locator or not depends partly on its signature, and partly on its role.
无论如何,WPF应用程序的组成根是-是否为应用程序是MDI应用程序不会改变它。
In any case, the Composition Root of a WPF application is the OnStartup method - whether or not an application is an MDI application doesn't change that.
由于在MDI应用程序中,您可以具有任意数量的子窗口,因此您很可能需要一个Abstract工厂创建每个ViewModel。
Since, in an MDI application, you can have an arbitrary number of child windows, you'll most likely need an Abstract Factory to create each ViewModel.
这篇关于WPF MDI应用程序中的组合根在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!