Reputation: 755
I noticed that every child of ViewModelBase in MVVM Light framework can overwrite constructor
public ViewModelBase(IMessenger messenger)
Would it be (architectionaly speaking) ok to use IMessenger to Model to ViewModel communication and update ViewModels when Model change?
It would mean that every Model would have its own IMessenger instance and every viewModel would subscribe to those messages.
Now i am using interface such as this
public interface IModel
{
event EventHandler<ModelStatusChangedArgs> StatusChanged;
}
and for each model which is kinda... pain and i feel i do something wrong.
Upvotes: 1
Views: 870
Reputation: 64121
Technically you could use it for every situation where you don't know who may listen or be interested in that event.
But MVVM Light is an MVVM Framework, which is actually used to allow loose coupling of ViewModels. Using it inside your Model would ultimately tie your Models to your MVVM Framework.
But there is nothing that prevents you from writing your own Event Aggregator/Messaging system (i.e. Domain Events). You can also remove the Messanger dependency from your ViewModels by implementing a wrapper around MVVM Light's messenger.
You usually want keep this "layer" dependencies:
And the MVVM frameworks reside in the "Application Layer", Models shouldn't be aware of it.
Upvotes: 2