When writing C# code, we rely a lot on instance events. A class might have some events that another class instance can register a handler and get notified when something happened; for example, classes that implement the INotifyPropertyChanged
interface raise the PropertyChanged
event when a property value is changed, or maybe we start a lengthy asynchronous task in another thread from a component we reference and we want to get notified about the progress. It's a great feature, but to make use of events the component that hooks to an instance event of another component must depend on it. Imagine if we have many cases of this communication: we will end up with spaghetti code and dependency references from component to component.
A common requirement is the communication of unrelated components, a ViewModel
to a ViewModel
or a service to a ViewModel
is common use cases.
An event messenger is solving this problem to send loosely coupled messages between components that...