I’ve been using the EventAggregator from Caliburn.Micro for a few weeks now and really enjoying it. The problem I’m running into now is say my service handles 3 types of messages. If each message type requires a different dependency I’m forced to inject a minimum of 3 dependencies into my constructor just to handle messages. The only time I would want my services to handle a message is when say I need to change the state of the UI.
Ideally, I would like each handler to be its own class. However, it doesn’t look like the EventAggregator provided by Caliburn.Micro creates instance of handler classes. This way if each message handler requires different dependencies then it won’t bother my core services.
Is there an alternative lightweight for using the same interface that Caliburn.Micro provides IHandle<T>, or something like ConsumerOf<T>? Since all messaging will be done within the application I don’t need a full fledged service bus.
I would recommend looking at MVVM Light’s Messenger class.
For example, rather than
You would do the following
Any class which wants to send messages simply calls something like the following