wpfmvvmmvvm-lightmessengerdataservice

What is the differency between Messenger service and Data service in wpf mvvmlight


I am trying to understand MvvmLight framework for Wpf. At the first look the messenger service and data service appear to do the same. They can both be used send data from ViewModel to the View. Is there anything more to this?

Please help.


Solution

  • A Data service is used to get data from the model (or back end server). The Messenger is a component that is used in order to allow the components (mostly view models but not only) to pass messages between them in a loosely coupled way.

    details: In MVVM, view models are usually not supposed to "know" each other. So when view model A wants to respond to things that happen in another view model B, it is not a good practice to for A to obtain a reference of B and attach an event handler. The messenger allows A to simply register to messages of a specific type, and for B to send this messages without any of them having a reference of each other. They only need to both "know" the message type.

    Data Service is a component that is used to obtain data from the back end. View models refer to it and request data.

    Hope this helps