I’ve got a plugin that needs access to certain information in order to populate its GUI elements properly. However, this plugin should not know about all other plugins, so I want it to request this information from the application.
In situations like this, I always create an interface for data exchange, and then pass this interface to plugins so that they can request the data when it’s needed. However, I recently started to use the MVVM light toolkit because it’s got some great features like RelayCommand and Messenger. In this case, I can totally see using Messenger — plugins don’t need the interface, because they can simply use Messenger.Default.Send<MyDataRequestMessage>(...). As long as they register the Receive handler, it’s all good… or is it?
Which method would you favor, and why?
In case of plugins, an aggregator like MVVM Light’s messenger is quite alright; alternatively, you could look at MEF (now part of .Net 4), which also enables auto-discovery and other such nice features, and you could use interfaces with that. So the answer is it depends 🙂 Personally I’d favor Messenger for its simplicity, unless it’s for a very large enterprise-y project maybe.