I have been looking at a couple of different approaches on how I can notify the UI about messages coming from the ViewModel, and wanted to see if this seemed appropriate or if it is too coupled. (We already have a static class that deals with notifications that I am trying to wrap for now, and maybe remove at a later time?)
INotifier
{
void Notify(Notification notification);
}
ConcreteNotifier()
{
void Notify(Notification notification)
{
Notification.ShowMessage(notification.Title, notification.Message, notification.MessageLevel);
}
}
Main will create ConcreteNotifier and pass it into each View, which will pass it into each VM
ViewModel(INotifier notifier)
{
_notifier = notifier;
}
DoStuff()
{
try
{
}
catch(Exception ex)
{
_notifier.Notify(new Notification{Title="DoStuff Error", Message=ex.Message, MessageLevel=Error});
}
}
This seems ok to me, however there is coupling due to the Notification
class. This is really just encapsulating parameters, so it is probably ok, but I wanted to run it past some people who are more familiar with MVVM and UI interaction. I only need to talk one way, so the Messenger pattern seems like overkill as I do not need to talk to other VM's, and this seemed like a simplistic way of dealing with this issue. Can anybody verify that this approach is ok, or if it has some issues with it?