I've been refactoring some code that was originally using the Messenger
in MVVM Foundation to now use the Messenger
in MVVM Light Toolit. One thing that I can't seem to find an equivalent for is the case where all you want to do is send a Token (i.e, the Token is acting as both a unique identifier for the message and the message itself).
Original Code (MVVM Foundation) - one string does it all
// send code
mvvmFoundationMessenger.NotifyColleagues("QuestionTimedOut");
// register code
mvvmFoundationMessenger.Register(
"QuestionTimedOut",
() => UpdateOnQuestionTimedOut());
New Code (MVVM Light) - is there a more elegant solution than this?
// send code
mvvmLightMessenger.Send("QuestionTimedOut", "QuestionTimedOut");
// register code
mvvmLightMessenger.Register<string>(
this,
"QuestionTimedOut",
token => UpdateOnQuestionTimedOut());
I realize I could explicitly new up a NotificationMessage
but that would add even more code.
Good point. I put that on the backlog for MVVM Light VNext.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With