helos,
my application allows users to write plugins (implementing IPlugin) that they can instantiate at runtime. on startup a directory of plugin .dlls is parsed, registering all the available plugins infos. at runtime a GUI is provided that lets users create instances of any of the plugins. this works.
but now i see MEF and hope i can do the same more elegant, codewise. what i got working so far with MEF: on startup i am doing an import of all plugins in a directory (that export IPlugin) and read out their informations (like name, category, author,...) which are encoded as exported metadata attributes to the pluginclasses. the import is done lazy so all the plugins are not actually instantiated on startup, which is important.
the problem is now that i don't see a way to elegantly instantiate a selected plugin at runtime given the additional complication that the plugins constructor is an importing constructor which is importing a reference to an IPluginHost (which it needs immediately to do some initialization).
together with a plugininfo i save the respective Export in a dictionary during startup. so when the GUI asks to instantiate a plugin given a specific plugininfo i have access to the Export (where Export.Value is my actual IPlugin). but from there how can i create an instance of the plugin and have it composed with the IPluginHost?
i gather i write my own ExportProvider that serves the IPluginHost whenever someone asks for it. but i don't have access to the assembly or the type of the specific plugin that would let me add it to a Catalog, add the catalog and ExportProvider to a container and call .ComposeParts on that container.
hope i made my problem clear, if not, let me try a short version of the question: isn't it a standard usecase for MEF to have a program that lazy-loads plugins on startup to parse the available plugins infos and then at runtime create specific instances given specific plugininfos? would be great to get a codeoutline of the steps involved.