Ever since I started using Caliburn.Micro I was puzzled why the EventAggregator used an interface in the ViewModel signature, like this
Agreed, the documentation is clear, in that you can Cast to see if the view model supports messaging, and if so automatically subscribe. But is that the only advantage? In the few EventAggregators I describe here it’s the only one using this technique. Anyway, a quick search showed that I was not the only person to wonder if it could be used without IHandle, as Thomas Oosterkamp shows. I created a small demo to test the idea, and decided I’d go a bit further to make a comparison with a few others. In fact, once you start searching there are many implementations of the Publish/Subscribe paradigm. I was also interested in publishing a message which was subscribed to in an independently loaded MEF module.
So attached is my simple demo of six EventAggregators. If your’s is not shown, do say and I’ll include it!
The demo is very basic. Each EventAggregator publishes your message when you press Send, and it is subscribed to in the same ShellViewModel and an MEF loaded module. The MEF module then re-publishes a new message with the same content, which is subscribed to back in the ShellViewModel. By the way, the MEF module is copied into the demo’s bin/Debug folder by a Build Event and so is entirely idependent. If your EventAggregator is shown, do let me know of any idea to enhance the demo to show off the best feature(s) of your implementation!
To be continued…