Where is the composition root in a WPF MDI application?

佐手、 提交于 2019-12-19 21:47:26

问题


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.

Thanks in advance.


回答1:


Whether or not a ViewModelLocator is a Service Locator or not depends partly on its signature, and partly on its role.

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.

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.



来源:https://stackoverflow.com/questions/9079530/where-is-the-composition-root-in-a-wpf-mdi-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!