What are the caveats of the event system built on Messenger rather than on classic .NET events?

Posted by voroninp on Programmers See other posts from Programmers or by voroninp
Published on 2012-11-14T06:35:40Z Indexed on 2012/11/14 11:18 UTC
Read the original article Hit count: 207

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?

© Programmers or respective owner

Related posts about .NET

Related posts about design-patterns