Are there any configuration file settings for MEF, or is everything done in code?
If everything is in code, what are some best practices for switching between different classes that do exports? i.e. if Class A and Class B both export IMyExport, what are some good ways to “configure” the app to use A or to use B?
As far as I know, MEF doesn’t have a configuration file. In the case that you want your application to use one implementation over the other, you could possibly create a new
ConfigurationCatalogwhich will get a configuration file as an input and will only export the parts it tells it to. It’s possible that something like that already exists in MefContrib, so I would check there.Other than that, it’s up to the classes themselves to decide which implementation they’d like to use. One possible way to achieve what you want is by using contract names
Then the class importing
IMyExportcan specify which of the parts it wants to useIf you know that a certain dependency
IMyExportcan be exported more than once, you can add metadata to the export and decide at runtime which of the exports you’d like to use according to its metadata. If you go with that direction, your code would look something like this