Click here to Skip to main content
11,433,997 members (59,356 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
I'm developing a .Net app with a modular architecture allowing it to load one or more "plugin" assemblies. Each assembly contains a class implementing an IPlugin interface which provides various methods for the hosting app to interact with the plugin.

The hosting app registers all these IPlugin classes via Windsor using the
container.Install(FromAssembly...
expression. It then instantiates the class as required to load the plugin into the main app window.

An IPlugin class will typically have dependencies on many other classes within its plugin. Currently I'm registering these with Windsor - the hosting app calls an IWindsorContainer in each plugin, allowing the plugin to register such classes. The IPlugin class's dependencies are then injected via its constructor.

Clearly this isn't a good design, as the IPlugin class shouldn't be requesting such classes (which are internal to that plugin) from a consuming application. Also, it means having to make these classes (or at least their constructors) public, otherwise they can't be registered with Windsor.

I now want to make such classes internal, but if I do this I'm not sure how the IPlugin class (which will be the only public class in the plugin) can get its dependencies. The options I can see are:-

1. Allow the class to instantiate its own dependencies, but this goes against good OO design - not loosely coupled, not testable, etc.
2. Instantiate its own dependencies using a service locator, but that's also frowned upon.
3. Continue to use Castle Windsor, ensuring that all classes are internal and with a public constructor. This feels a bit hacky, and still means my IPlugin class will have a constructor requiring all these types to be injected.

Any advice or suggestions much appreciated!
Posted 12-Oct-12 6:34am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This isn't a full solution, but if you haven't already then have a look at both nopCommerce [^]and mainly Umbraco[^], which both implement a plugin architecture.

nopCommerce based it's pattern on Umbraco, which is a pretty well established CMS - so it might give you some good ideas.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.150428.2 | Last Updated 12 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100