0
votes

Team,

I am learning Mvvm with MvvmLight framework. The framework creates the Views, ViewModels and Locator all in one project. But in practice we would want to keep the View models in a different project. So now the question is what would be the ideal place for ViewModelLocator. Should this be in UI layer or ViewModel class library. MvvmLight creates locator in ViewModels folder along with ViewModels.

Thanks and REgards Dev1

1

1 Answers

2
votes

Hi and welcome in the wonderfull world of MVVM and WPF.

Your question is a bit tricky because the good response, as often for design question would be: it depends...

At a first approch I would recommand to let it in the view project. Because the Locator is the way for specific views to localize required viewModels.

But I guess that if you use another project for your viewModel, the aim is to reuse this project (therefore the viewModels) for some other software? In this case I would say: will your ViewModelLocator will be reusable as well?

If yes (meaning it will locate the same viewModels each time foreach view project using it), it is logical to let it in the viewModel project.

If no, it is probably better to have a specific Locator locating only required viewModel foreach view project.

Hope it helps.