windows-phone-7mvvm-light

mvvm light messenger check if a class is already registered?


In MVVM Light, can we check if a class is already registered? i.e. if I call the following method twice, it is registering twice. I need it only once.

Messenger.Default.Register(this, message => DisplayError(message));

which is a good place to register an instance to Messenger? Constructor or Loaded event handler?

which is a good place to unregister?


Solution

  • At the moment, there is no API to check if an instance or a class is registered in the Messenger. You need to track this down yourself.

    I usually register in the constructor, and expose a Cleanup method where I unregister before the object is removed.