Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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
C#
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

1 solution

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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900