2

everyone

The problem is if there exists two exported components which have the same export signature but only one should be imported ( this is possible, the practical example is install new plugin to replace the old one without uninstall the old one. ). We can provide a configuration file to tell which component should be imported, but the question is how to tell MEF the right selection?

I have three methods:

  1. Use a custom catalog, filter the available plugins. But suppose the situation that A imports component A and B imports component B while the component A and B have the same export signature. A custom catalog cannot handle this except we create new custom catalog for each component.

  2. Interception in MEF composition. I am not sure if it is possible and I don't know how. But if there's a way let us intercept in composition process, this could be the best one.

  3. Use a import wrapper instead of real interface. When the component is constructing, it will initialize the wrapper and let the wrapper handle the selection logic ( such as prompt a window and let user select one or read configuration )

Simon. Li
  • 404
  • 2
  • 11

1 Answers1

2

what about the use of [ImportMany] to get all possible imports for the same signature and then choose the one you want for certain condition (config file or something else) from this list of imports?

EDIT: i like your suggestion number 3, i think this one could be easy. your wrapper handles the real interfaces with [ImportMany] and the plugins ask your wrapper for GetTheOneInterface().

blindmeis
  • 22,175
  • 7
  • 55
  • 74
  • Yeah, [ImportMany] could solve, but this will force all composition components to handle plugin selection logic itself. I am trying to avoid this. – Simon. Li Feb 08 '12 at 06:43
  • see http://stackoverflow.com/questions/7750640/intercepting-dependencies-in-mef, this may help, implement a ExportProvider may meet method 2 – Simon. Li Feb 08 '12 at 07:56
  • thx for the link. if you got your stuff working please post this here as an answer. – blindmeis Feb 08 '12 at 09:35