views:

115

answers:

2

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?

+1  A: 

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.

Alex Paven
I'm currently using MEF + a data interface already. I also like the Messenger because it makes things easy, but I'm just not familiar enough with it to know right away all of its potential caveats.
Dave
I'm not aware of any, I've used it already in two medium-sized projects and I'm happy with the outcomes. Plus, if you find any downsides, it's easy to modify the code to fix or work around them :P
Alex Paven
+1  A: 

As Alex said, MEF was created just for this purpose. If you need to manage plug-ins, you're probably going to end up duplicating a lot of work that MEF provides for you if you don't use it.

There's no reason you can't use both MEF and MVVM Light. Your idea of communicating from your plug-in to your app using MVVM light's messenger is intriguing, and I hope it works for you. However, keep in mind that any plug-in could register to receive these same messages and you could end up with one plug-in receiving another plug-in's messages. This might not be an issue for you, but if you don't control who writes these extensions you definitely have a security hole there.

Good luck!

Matt Casto
@Matt thanks -- I have been using MEF for a while in my app, and I really like it, and I would use it for everything if debugging part compositions wasn't so painful. You should check out my most recent question at http://stackoverflow.com/questions/3696893/mef-error-was-circular-dependency-and-is-now-something-else, which is directly related to this question. I ended up going the MEF route and have run into an interesting problem!
Dave