Creating a Plugin enabled
Application : Part 1 of 2
In this article I am trying to show how to create a plugin
enabled application using .Net Reflection.
The plugin enabled application loads an associated piece of software
during the runtime. There should not be
any design time binding for the specified component.
Advantages of Plugins
We can see lots of plugin enabled applications for example
Winamp. The plugin enable application
provides the following flexibilities:
-
Reduced Size in Initial Deployment
-
Incrementing the modules as plugins
-
Customers can be benefited by choosing Plugin
Modules thus reduction in Cost
How Plugins works?
There will be 3 components in a plugin architecture
application.
1)
Plugin Container
2)
Plugin Interface
3)
Plugins
The Plugin Container will serve as the host holding all
plugins found in runtime.
The Plugin Interface provides as a standard of communication
between the Container and Plugins.
The Plugins are the actual piece of software which are
located and loaded by the Plugin Container.
Execution
The plugin enabled application executes as depicted in the
image below. After the application is
executed, it will search for the plugins of associated interfaces. If any plugins found they are instantiated
and loaded into the application.

Diving into the Code
I hope we had enough of theories. Now let us focus on how to build the actual
code. In our example, we are trying to
load plugins which contains forms. There
is one Plugin.Core application which
will perform as the Plugin Container and n number of plugin dll's which
contains the forms.
Each form found will be having a display name so that we can
show it in the toolbar.
Component 1: Plugin
Container .exe
This is a Windows
Forms Application containing the Main Form to contain the plugins.
Component 2: Plugin.
Interface.dll
This would be a Class
Library containing the IPlugin
interface.
public interface IPlugin
{
string Text
{ get; }
Form
Form { get; }
Color
BackColor { get; }
}
There will be a PluginLoader
class which basically takes care of finding the plugins in given folder and
loading them into the system.
Component 3: BlueForm.Plugin.dll
This will be a Class
Library project containing the plugins.
The plugins are nothing other than classes which implements the IPlugin interface.
In our project, we are creating a plugin class named BlueFormPlugin which holds a form.
Note
For the time being I have used Windows Forms for plugin
example, but we can extend the same idea to ASP.NET, WPF, Windows Mobile
applications too.
Summary
In this article the basic components of building a the Plugin based application is
explained. In the next part we can see
the inner details of how the plugin can be identified and loaded into the
application using Reflection.