Alex Rivera | Logout

How to implement properly plugins in C#?

Asked 2010-04-15T09:22:04.293
10

I'm trying to add plugins to my game and what I'm trying to implement is this:

  • Plugins will be either mine or 3rd party's so I would like a solution where crashing of the plugin would not mean crashing of the main application.

  • Methods of plugins are called very often (for example because of drawing of game objects).

What I've found so far:

Edit
Report

1 Answer

1

I used this tutorial as the basis for my own plug-in architecture a couple of years ago. My architecture was, I believe, a relatively simple architecture, but I hit some problems when it came to passing messages between plug-ins.

If you're intent on writing your own architecture, then fair enough, but I would warn against it. It's no small undertaking, and sooner or later you're going to run into some major design considerations, like message passing, which are non-trivial to solve (if admittedly simultaneously quite interesting and frustrating). There is a tremendous amount of value in using something like MEF that solves these problems for you, and provides a really nice API and framework upon which you can build you plug-ins.

Furthermore, MEF will end up being distributed as part of your application, so you don't need to get your users to download it separately; it's an "invisible" dependency as far as they're concerned, and a light-weight one for developers, including yourself. It's also the official plug-in architecture for Visual Studio 2010, so it has a lot of weight in the .NET community, and there will only ever be more developers able to write plug-ins for your app if you use it too.

Hope that makes some sense.

answered 2010-04-15T09:47:00.007

Your Answer