At work, we are about to build a new internal tool for administration of different systems. We developers need certain applications and the sales department needs some other ones. All the different people need to be able to administrate different systems, so we decided to create one application that hosts only the applications the individual needs.
Last weekend I played with a generic application that hosts other applications by using reflection. The Plug-in Application does nothing but manages the different plug-ins and let you add and remove plug-ins as you please. When a plug-in is added, it is added to the menu so that every time you open the application, you have easy access to the plug-in.
Each plug-in is in essence a .NET Windows Forms application, but you can also compile the WinForm into a .dll file so it cannot be opened outside the application.
This is what it looks like when the plug-in “TestForm” is running in the application.
Now the plug-in is maximized.
By clicking on the menu item “Manage Plug-ins” it pops up a manager that lets you add and remove plug-ins.
How it works
To make your Windows Forms application compatible with the application, you need to let the main form inherit from a class called PluginForm. The PluginForm resides in its own assembly and is also referenced by the Plug-in Application. It only contains a property called Description and that is used to display tooltips on the menu and in the Plug-in Manager. Your main form needs to inherit from the PluginForm in order to know which form is the one to use in the Plug-in Application.
When you add a plug-in then the Plug-in Application creates an XML document that describes its location, icon, description and name. Because it does not copy the .exe or .dll file but only points to it, means that app.config and other files still work with the plug-in.
This is a simplified version of the one we need at Traceworks where we also needs security and other features. The Plug-in Application is so simple that it is easy to add such features.
The solution contains three projects. The application, the PluginForm base class project and a test plug-in.