Components
File: Type-Safe Plugin Framework
- Uploaded:
- September.01.09
- Modified:
- September.01.09
- File Size:
- 20 KB
- Downloads:
- 282
- Version
- 1.0
Plugin framework that allows you to build applications that can be dynamically extended. Using plugins is also an elegant way of enforcing decoupling of application modules and avoiding dependency creep. Doesn't require any modification to the plugin classes (no custom attributes and no special base classes).
Details
Here's a piece of code that has been sitting in my support library for some time already and is being successfully used for all kinds of plug-ins. Plug-ins are an elegant way not only to make applications extensible, but also to enforce separation: if an assembly does not have a reference to another assembly, no "dependency creep" will happen and separation is guaranteed.
Plugins are quite similar to Dependency Injection through an Inversion-of-Control container with auto-wiring, but without recursive lookups and requiring you to write the code that decides which types are suitable as implementations yourself. If you don't know what I'm talking about here, don't worry, you don't need to know a thing about IoC containers to use plugins, though I highly recommend reading up on the topic because it's an excellent way to keep on top of larger projects :)
My plugin library splits plugin management into three parts: First, there's the
"Repository", which stores the loaded plugin assemblies. Then there are
"Employers" which will pick the types from the plugin assemblies that fulfill
the employer's requirements (an example criterion could be: all non-abstract classes deriving
from IGraphicsDevice). Finally, there's the "PluginHost" which will
run an employer on the types found in the assemblies in its repository.
Example
This is the example also included in the downloadable example project
Features
- Dynamic loading of assemblies as plugins
- Plugins are fully type-safe
- Freely definable employment criteria for plugin types
- Freely controllable employment action (built-in employers include factory creation and instance list)
- 100% unit test coverage for the whole code
The plugin code is part of the Nuclex.Support library from the Nuclex Framework. You can
find the most recent release of the code on the framework's CodePlex site:
http://nuclexframework.codeplex.com/