My application allows users to write plugins (implementing IPlugin) that they can create at runtime. At startup, the .dll plugin directory is analyzed, recording all available information about the plugins. At run time, a graphical interface is provided that allows users to instantiate any of the plugins. It works great.
But now I see MEF and hope that I can do the same, but in a more elegant way.
What I have worked with MEF so far : at startup, I import all the plugins in the directory (which exports IPlugin) and read information such as name, category, author, etc ... They are encoded as exported metadata attributes into plugin classes. Import is lazy, so all plugins are not created at startup, which is important.
The problem is that now I don’t see a way to elegantly create an instance of the selected plug-in at runtime, given the additional complication that the plug-in constructor is an import constructor that imports a link to IPluginHost (for which some initialization needs to be done).
Together with plugininfo, I save the corresponding Export in the dictionary at startup, so when the GUI asks to create an instance of the plugin based on a specific plugin, I have access to Export (where Export.Value is my actual IPlugin). But where can I instantiate the plugin and create it using IPluginHost?
I'm going to write my own ExportProvider that will serve IPluginHost when someone asks for it, but I don’t have access to the assembly or type of a specific plugin that would allow me to add it to the directory, add the directory and ExportProvider to the container and call .ComposeParts in this container.
, , , :
MEF, , lazy- , , plugininfos? .