This project has moved. For the latest updates, please go here.

Locator acrossed multiple projects

Apr 6, 2010 at 10:49 PM

I just cam across your presentation from Mix10 and I really enjoyed it. I am new to MVVM and WPF.

Do you have any recomendations for using the Locator acrossed multiple projects. For example I thought of placing the Locator in a Foundation project but putting it there were it doesn't know of any of the other projects doesn't make sense. And if I put it in the wpf app doesn't really make sense if I choose to also allow for xbap capability.

Any suggestions would be greatly appreciated.

Apr 12, 2010 at 8:53 PM

Nothing yet huh. I have seen a response to everyone else. I definately don't feel the luv.

Apr 13, 2010 at 8:39 AM

Hey dude :)

Sorry about that. You should see my inbox, I am definitely not ignoring only you ;)

I have to say, your question made me wonder why you would want to do that. Are you trying to reuse the same code in multiple projects (for example have one version for WPF and one version for Silverlight)? If so, it is easier to link the code files. For more information on this, try to check my MIX09 session at where I was sharing some code in a similar fashion.

If I misunderstand what you are trying to achieve, please comment here, and I will do my best to reply faster ;)



Apr 13, 2010 at 2:01 PM

Basically, my application is setup with modules. I have the main shell, which can be interchangeable (WPF, XPAP), Foundation module with most structure, then multiple projects containing individual modules. Each module cantains multiple controls that can be added to the main display. Each module will conincide with a navigation button. When someone clicks the navigation button I want the corrisponding module to load into view.

Apr 13, 2010 at 2:26 PM

By the way I figured you were busy. It was either that or my question was so rudimentry that it should have never been asked. But tx for the response.

Apr 13, 2010 at 2:45 PM


OK I see what you try to do. In such a case, i would rather have one ViewModelLocator per module, and consider each module to be an encapsulated world. To communicate from one module to the other, use the Messenger class. This is becoming a very popular combination, for example in MEF + MVVM Light.

If you check Glenn Block's blog, he made some work with MEF and the MVVM Light messenger. I think that this would be a better idea than trying to have one global locator for the whole application.

Hopefully this helps,


Apr 13, 2010 at 3:42 PM

To verify are you speaking of this post? which links to

Apr 13, 2010 at 4:51 PM

No, that article you mention shows a way to define a generic ViewModelLocator using MEF to wire the ViewModels and the Views. Interesting stuff for sure, but it is not what i meant.

I rather referred to the Building Hello MEF series that starts here: Make sure you check all the articles in this series.

Glenn is very fond of the Messenger to communicate between modules, it makes the decoupling very easy.



Sep 3, 2013 at 12:15 PM
The MEF part you show does not show the specifics of how to deal with multiple ViewModelLocators. The problem is composing a ViewModelLocator from plugins so that it has the various properties needed for Views to lookup their ViewModel.

We already use MEF to collect ResourceDictionaries from plugins that contain DataTemplates for View / ViewModel relations. I guess we could add ViewModelLocators with slightly different names for each module and import those at Application level, eg. Plugin1Locator, Plugin2Locator and Locator for the main application.

Is this what you had in mind?