Providing a programming interface to a plugin

O

Olie

I was quite surprised to find virtually nothing about this but I may
have been searching for the wrong thing.

I want to know the best way to provide a programming interface to a
plugin. I already have a plugin architecture that allows the
application to call code in a plugin but I want the plugin to also be
able to call code in the application.

I can think of many ways to do this but I am not sure the best way:

Option 1:

The plugin inherits a class that has one function called
GetInterface(), This returns a reference that can be cast to different
Interface types.

Option 2:

The plugin is passed a reference to the application interface which
contains all the callable functions.

Option 3:

The plugin can create an object that has all the API functions in it
e.g. Stop, Pause and Play. (The problem with this is how do you
actually connect those functions back to the main application.) I
suppose this would be similar to the office api or activeX interfaces.

I want to choose the best way that will also allow me to update the
API without breaking any existing plugins.

Any advice is welcomed!
 
N

Nicholas Paldino [.NET/C# MVP]

Olie,

I would recommend defining two more interfaces. The first is an
interface that your application object implements. The second is one which
your plug in implements. The interface that the plugin implements (in
addition to the one it already implements) has one method which allows you
to assign the interface for the application to it. It's a way of the plugin
to say "I want a reference to the host".

You have a separate interface for your host (which is contained outside
of the host assembly) so that you don't have to worry about versioning as
much.

Then, you can do your plugin processing normally.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top