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

ViewModel Service Locator

Nov 18, 2010 at 3:25 PM

How do you go about registering a service for your view model via dependency injection and/or mef importing constructor when registering your views to your viewmodel?

public class MyViewModel : BaseViewModel
	private IService _service;
    public MyViewModel(IService service)
        _service = service;

public ViewModelRoute Binding 
    return ViewModelRoute.Create(Constants.MYVIEWMODEL, "Shell"); 


Nov 18, 2010 at 11:19 PM

So a simple service just becomes


on the service and

[Import] IService (public) on the view model.

For more complex scenarios, I might use a locator like this:

Nov 19, 2010 at 11:14 AM

ok, thanks