PlugIn/AddIn references to main application.

Jun 30, 2009 at 7:01 PM

Is it possible, when creating an extensible application using MEF, to be able to create plugins/add-ins that contain no references to the main application? I use the directory catalog, and my main application has no references to my addin, but my addin has to contain a reference to the interface library connected to my main application in order to compile (because I am calling methods inside a class in the main aplication). I think the extensibility and possible addin distrribution would be far greater if the addin did not have to reference the main application, especially because to reference the application an exact path must be specified. I had considered removing the reference and creating another directory catalog in the add-in with a path to the main app, but was not sure about having two catalogs.

Jun 30, 2009 at 10:17 PM

The typical way that you would accomplish something like this is via a third assembly which is referenced by both the main application and the plugin application. Third third assembly would contain the interfaces in which your plugins and application use to communicate. Imagine a loosely coupled example like:

// contracts.dll
interface IPlugin {
   void InitializePlugin(IApplication app);
interface IApplication { // some API }

// plugin.dll - references contracts.dll
class Plugin : IPlugin { }

// mainapp.exe - reference contracts.dll
class Application : IApplication
   IPlugin[] Plugins { get; set; }

  // Setup your DirectoryCatalog
  // some point call plugin.InitializePlugin(this)

Hope that helps with your question.

Jul 1, 2009 at 12:20 PM
Edited Jul 1, 2009 at 5:05 PM

That's actually what I'm already doing. The app itself and the plugin may be loosely coupled, but they are both coupled to the interface library. The plugin would still need to hold a reference to the interface library, which could decrease extensibility. If I wanted a customer to download a plugin for my product, he would not be able to just drop it in a folder: he would also have to specify a reference to the interface. Is there any way around this? Thank you for your time.

Jul 1, 2009 at 5:02 PM

I'm not sure what you mean by specify a reference to the interface. Sure while developing the plugin the developer of the plugin would need to reference this common interface assembly. However, since your interface assembly is already loaded in the running application, during deployment they only need drop their plugin in the extensions directory. In other words they shouldn't need to deploy the common interface assembly.

Using statically typed languages such as C#, there isn't really a good way to completely decouple two assemblies, there has to be some common interfaces they communicate through.

In .Net 4.0 there is a new feature commonly referred to as No-Pia ( that will allow you to do some more decoupling but even in this case you need a common reference assembly similar to the common interface assembly we've already talked about.


Jul 1, 2009 at 5:05 PM

Ok Thank you.

Jul 16, 2009 at 12:18 PM


Check the example which i posted on my blog.

Jul 17, 2009 at 12:21 PM


Thank you. I had actually come across your blog earlier.