Click here to Skip to main content
15,881,380 members

Looking for some advice on handling dependencies

AndyStephens asked:

Open original thread
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!
Tags: C#

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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