Search code examples
wpfsilverlightwindows-phone-7windows-phone-8mvvm

Service call from MVVM


Which is the right place to call service in MVVM pattern, View Model or Model? I am planning to invoke service from ViewModel, get the JSON and convert it to corresponding model. The reason I am not invoking service from Model to keep the Model decoupled from service.

Is this approach right or I should call service from Model?


Solution

  • Typically VM is responsible for making service calls. A sample call stack can be:

    UI Event (View) => ICommand Execute (VM) => Service Call (VM).

    It's advisable to have a re-usable Service Tier utilising the same domain objects as your app - as it allows the service-calling logic to be shared by multiple VMs (added from comments).