c# - Loading plugins at runtime with MEF -


My application allows users to write runtime (Implementing IPlugin) that they can institute on runtime There is a directory of plugins at startup. Dlls are parsed, entering all available plug-in notifications. At runtime a GUI is provided that makes users an example of any plugin. It works fine

But now I am looking at MEF and hope that I can do this, but in a more beautiful way codewise

I now I'm working with MEF : On startup, I am importing all the plugins in a directory (Export IPLGen) and read information such as Name, Category, Author, etc ... Export for these plugin sections Metadata are encoded as attributes to import Is the Serous, so not Instityueted all plugins at startup, which is important.

The problem is that now I do not see any way to choose beautifully to choose from. At the runtime, the plugin provides additional complexity that the plugins manufacturer is an importer constructor Importing the context of an IPluginHost (which is necessary to do something initially)

With a plugininfone I save the related export in a dictionary during startup, so when a GUI asks to request the plugin to give a specific plugin plugin, I have export (where Export is .value is my actual ipeligin). But how can I make an example of the plugin from there and what is written with the IPL taginhost?

I have collected, I would like to write my own export provider which whenever I ask for it, but I can not use the IPluginHost assembly or specific plug-in that gives me a catalog , Add catalog and export provider to container and call. Compass ports on that container

I hope I have clarified my problem, if not, then I should try to make a short version of a question: this is a standard There is a program for MEF that does not have the lazy available plugins loads the plug-in at startup to parse Infos, and then specific specifications given on the runtime make specific examples? The steps involved will be great for getting a codeoutline.

If I understand correctly, you can potentially trigger multiple plugin instances Looking for a route is the same plugin

You need to declare this type of import and then select the right factory based on the metadata. You will take care of any import required by ExportFactory.CreateExport IPlugin examples, like IPluginHost you have mentioned.

Note that in the first release only ExportFactory was available in the version of silver version of MEF, in order to get it in the desktop version, you currently have the latest version (MEF 2 - Preview 1) is required. There is a known problem in importing ExportFactory through the constructor, so use the property.


Comments