What are the caveats of the event system built on Messenger rather than on classic .NET events?
- by voroninp
MVVM Light and PRISM offer messenger to implement event system.
the approximate interface looks like the following one:
interface Messanger
{
void Subscribe<TMessageParam>(Action<TMessageParam> action);
void Unsubscribe<TMessageParam>(Action<TMessageParam> action);
void Unsubscribe<TMessageParam>(objec actionOwner);
void Notify<TMessageParam>(TMessageParam param);
}
Now this model seems beneficial comparing to classic .net events. It works well with Dependency Injection. Actions are stored as weak references so memory leaks are avioded and unsubscribe is not a must.
The only annoyance is the need to declare new TMessageParam for each specific message.
But everything comes at a cost. And what I'm really worried about is that I see no shortcomings of this approach.
Has anoyne the experience of some troubles with this design pattern?