This project has moved and is read-only. For the latest updates, please go here.

ViewModel Service Locator

Nov 18, 2010 at 4: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 19, 2010 at 12:19 AM

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 12:14 PM

ok, thanks