I need to design a simple plugin framework for our application (.NET, WinForms 3.5).
The extension points will be several application events/scenarios that the user could “hook” into using a plugin, to perform a certain operation.
The way i would like this to work is:
-
Have a Plugins folder where users will place plugin DLLs (assemblies containing types derived from a specific base class/marked somehow).
-
Have my application plugin system locate these files and register them for later usage.
-
Invoke the right plugin at the right time (for example: OnException, OnLog, etc).
If i will create the plugin object (new it up) at registration, the DLL would be loaded into the process memory.
I am looking for an easy way to do the registration, and only “lazily” load the plugin assembly, when needed (IF needed at all).
You have a couple options for this – If you are able, you could require that each plugin provide a manifest or some other file that describes itself, and then you could examine all the manifests and load the appropriate plugin when necessary. This avoids examining the assembly, but it does require consistency between the manifest and the assembly, which can be tricky.
Otherwise, as you’ve indicated, examining the plugin assembly will load it into memory. The only way I’ve discovered to avoid this is to load them into a separate
AppDomain, examine them and capture necessary information, then unload thatAppDomain. There is an example of doing this for PRISM somewhere (I can try to track it down), but I’m not sure what framework you’re using (MEF, MAF, PRISM, IoC, etc.).