Building a Plugin Architecture with C#

Written By: Nathan Baker

- 06 Mar 2006 -
















Description: I will show how to use C# to create an extensible application using plugins.

  1. Introduction
  2. Beginnings
  3. Let's Write Some Code
  4. The Host Application
  5. Writing a Plugin in C#

Introduction

OK, so we all understand the basics of application development. You write a program, distribute it, and it does what you say it will (we hope). This model has been around as long as computers have. However, there's a newer model that has recently gained in popularity, a model that allows a programmer in Germany to add functionality to a program written in Japan and run on a computer in the US despite the fact that the German programmer has never even met or talked to the developer for the original application. This model is a plugin architecture.

Basically, a program that supports plugins can dynamically load unknown code and call it as if it were a part of the original program. This means that if you're great at writing sound processing code but horrible at doing a user interface, you can write a sound plugin for a program like Winamp and it can load it, even if you know nothing about how Winamp works internally. By using an extensible architecture, you put more power in the hands of your users.

OK, you've convinced me! What next?

For this project, I will walk you through the steps of creating an extensible architecture using C#. We will create the base application (the plugin host), and then we will extend it by writing a plugin in C#.

Although the application we end up with won't be one that you could sell to a customer, I hope that once we're done you will have a good understanding of how to load unknown code at runtime and how to design an application around objects whose internal workings are not known to you, the developer.

Administrivia

The sample code is written using Visual Studio .NET 2005 and the .NET runtime version 2.0. VS2005 solution files cannot be loaded by visual studio 2003 or lower, but you can still import the .cs files and view the code. The Express Edition of C# version 2.0 is available on Microsoft's MSDN site and should be able to compile and run this code.

Next >>