tags:

views:

105

answers:

6

I'm starting a new project which would greatly benefit from program add-ons. The program in its most basic form reads data from a serial port and parses it into database records. Examples of add-ons that could be written would be an auto-archive add-on, an add-on to filter records, etc. I'm writing both the program and the add-ons, but some customers need custom solutions, so instead of branching off and making a completely separate program, add-ons would be great. The simplest add-on would probably be a form who's constructor takes an object reference, manipulates the object in some way, then closes.

Unfortunately, I have absolutely no idea where to start coding, and almost as little idea where to search. Everything I search for turns up browser add-ons. From what I have gathered, I need to look into dynamic loading DLLs. Besides that, I'm clueless. Does anyone have any good resources or examples I that they know of?

I'm happy to provide more details, but this project is in its inception, so I don't have a ton of specific details (specifics kind of defeats the point of add-ons, too.)

A: 

I think Reflection will play a major role.

I expirimented with an app that had a plugin folder. A filesystem watcher would watch the folder, and when a new DLL was placed in it, it would use reflection to determine which types of plugins it included, loaded them, and added them to the list of available classes, etc.

Neil N
+2  A: 

A very basic description (basically, your plugins must implement a special interface):

http://martinfowler.com/eaaCatalog/plugin.html

Much better article, in C#:

http://www.drdobbs.com/184403942;jsessionid=TVLM2PGYFZZB1QE1GHPCKHWATMY32JVN

FrustratedWithFormsDesigner
+5  A: 

This is a simple example to illustrate the basic technique.

codeproject.com - Plugin Architecture using C#

This article demonstrates to you how to incorporate ... as a plugin for another application or use it as a standalone application.

in .NET 4 you now have the Managed Extensibility Framework (MEF) to do much of the plumbing.

In .NET 3.5 you had the System.AddIn but it was deemed by many to be far too complex.

codeproject.com - AddIn Enabled Applications with System.AddIn

AddIns (sometimes called Plugins) are seperately compiled components that an application can locate, load and make use of at runtime (dynamically). An application that has been designed to use AddIns can be enhanced (by developing more AddIns) without the need for the orginal application to be modified or recompiled and tested

Ryan
+1 for adding MEF
Randolpho
A: 

Try using the term 'add-in' or 'plug-in' for your research instead of 'add-on'. That should help some.

If you're using .Net 4, there's an add-in namespace in the framework that will get you partway there.

Writing plug-in support for an app is no simple task. You'll have to maintain pretty strict separation-of-concerns across your interfaces, you'll need to provide an interop library that defines ALL of the supported plug-in types, and you'll want to do some research into dependency injection & inversion of control, in addition to the previously-suggested reflection research.

It sounds like you might have a busy weekend doing research.

Toby
+4  A: 

You really need to look at Managed Extensibility Framework (MEF). This is specifically designed to help support add-ons and other extensibility.

Robaticus
I don't know if you or @dthorpe posted first, but have a +1 anyway!
Randolpho
Jinx! We posted nearly simultaneously. (within 10 seconds of each other)
dthorpe
@dthorpe - Now I owe you a Coke! (that was our regional variant of "Jinx")
Robaticus
@Robaticus: Deal! I'll start a tab for you. :P (Much better than having to hold your breath til someone says your name)
dthorpe
+6  A: 

You should seriously consider using the Managed Extensibility Framework (MEF) to handle your plugin architecture. It requires thinking about things a little differently, but it is well worth the mind-stretch.

dthorpe
+1. I came in here to pimp that and found it already pimped. Good pimping, sir!
Randolpho
MEF is totally pimpworthy
dthorpe
MEF is excellent! It's exactly what I was looking for. I'll have to mess around with it some more, but I already have a simple form which allows you to add buttons to it. Awesome!
Daniel Rasmussen
Another alternative is Mono.Addins (monoaddins.codeplex.com), which besides the basic support for class and interface extensibility, it provides some nice features such as data extensions, add-in dependencies, and tools for managing add-in repositories.
Lluis Sanchez