Question

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 )

Was it helpful?

Solution

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().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top