Follow @RoyOsherove on Twitter

About Dynamic Plug-in Discovery And AppDomains

I've gotten several comments on my Plug-ins article which was published both here and on CodeProject. One of them mentions the obvious missing feature for a plugin architecture - Dynamically discovering plugins without the need for configuration files.

In essence, what you would do is go through the folder in which application is located, and search for assemblies with types that implement the "IPlugin" interface. One problem here - In order to check an assembly, you must load it; assemblies can't be unloaded without unloading the whole AppDomain in which they reside .If you unload your own appDomain - you're basically shutting down you application. problem.

A way to resolve this would be to load a separate AppDomain and load the searched assemblies into that one. Then make a separate list of the assemblies that match your criteria and only load those into a seperate AppDomain. This gives you 2 advantages:

  1.  You can dynamically search for added or changed plugins at runtime
  2.  You don't save 'garbage' assemblies at run-time.

I'll try to implement this solution in the coming days. Meanwhile, here's a good MSDN article about loading and unloading AppDomains.

AppDomains and Dynamic Loading

I'm also thinking of purchasing this book:

C# Threading Handbook

Anyone know about it? Other recommendations?

.Net Developer Journal May Issue PDF download