MVVM: When EventAggregator (aka MessageBus) is an Anti-Pattern

Very often we can see that developers tend to use static message buses for all kind of interactions between objects. For those, who unaware of this pattern I want to recall that this pattern allows organizing loosely coupled communication channel between objects which don’t want (or can’t) to know each other.
Let’s have a brief look at how a regular example of using this pattern may look like:

public class Sender {
    private readonly IEventAggregator eventAggregator;

    public Sender(IEventAggregator eventAggregator) {
        this.eventAggregator = eventAggregator;
    }

    public void Action() {
        eventAggregator.Publish(new Message());
    }
}

public class Receiver : IHandle<Message> {
    public Receiver(IEventAggregator eventAggregator) {
        eventAggregator.Subscribe(this);
    }
    public void Handle(Message message) {            
    }
}

Continue reading