views:

184

answers:

3

We have an application supporting plugins via interfaces. On the other side plugins contain lots of logic and code in themselves. Plugins have dependencies (project and dll references) to application libraries beside the interfaces that application exposes.

Application core libraries have lots of reusable components that can be used in plugins. But if any of these components change in anyway, both the plugins and application are affected, as both have dependencies.

Is it acceptable to have plugins containing dependencies on the system, that plugins extend? What are the best practices on this issue?

Please share your thoughts and experiences.

A: 

I think it is totally fine to have you plug-ins referencing off of your core. Now you’re talking about project and dll references, so you must be using c#, vb or c++, these solutions all should be fine to use.

I typically have two projects, to get around the circular dependency.

  1. Project Base, Interfaces, Exceptions
  2. Logic/Configuration/Plug-in Loader

There are three ways I typically load plug-in

  1. Out of a directory using loops and the filesystem watcher (slow but effective)
  2. Use your own configuration section in .net using named types (recommended and fastest)
  3. Load them from a database (good for scalability)
Elijah Glover
+1  A: 

Take a look a Mono.Addins, even if you are not developing in C#, it will give you some great ideas.

The simple solution is to define a version system for the plugins and the core, so the core can read which version of itself the plugin needs. That way is easy to prevent the load of a plugin which was meant to be used with a previous version of the core.

Ricky AH
+1  A: 

I think there are two answers to your question, depending on the level we're talking about:

  • yes, it's fine to have a dependency of the plugin on the plugin host. The host is coordinating the use/execution of the plugin, but there is no reason for the host not to provide functionality to help the plugin do that. Extending that a little further, the host's dependencies may or may not be fair game for the plugin to use (this goes into the territory of "it depends...").
  • no, the plugins should not depend directly on code that the host could provide, except those objects that the plugin directly passes in. This is more a distrust on global state than a fear of circular dependencies.
jamesh