David
David

Reputation: 1841

Use two identical classes/interfaces under different namespaces interchangeably?

I'm writing a web application for which I want to allow 3rd party developers to write "plugins" that can be loaded into application to modify the behaviour from the standard.

So conventional wisdom would suggest having something like this:

public interface IPlugin {
    void Execute (IPluginContext context);
}

Third party developers can then implement that interface, monkey around with the context, then register their code with the application to execute (usually attached to some message and pre/post condition).

My problem is how to expose these interfaces. The simplest thing seems to be create a MyApplication.SDK library that has only the interfaces and classes I want to expose. However that means my main application needs to reference this library, so the SDK is being used to build the application, which sounds a little back-to-front.

Is there anyway to have an IPlugin interface in both applications and for the main web application to use the SDK's IPlugin interface as if it is its own? As in they are both identical?

Upvotes: 1

Views: 107

Answers (1)

Tyree Jackson
Tyree Jackson

Reputation: 2608

When you build a pluginable system, the interfaces and supporting classes that you want to expose to plugin authors are a contract between you and the plugin authors. Therefore, it is right for both your application and their plugins to reference the same contract library. Therefore you should put your interfaces and supporting classes for your plugin architecture into the SDK library.

Also, by having the SDK library, you can release new versions in new libraries later and potentially support multiple versions of the plugin interfaces which will allow you to evolve that capability over time while maintaining backwards compatibility.

Upvotes: 4

Related Questions