Common Dependency Injector

Oct 23, 2008 at 5:22 PM
You guys did great job defining common service locator interface and making it implemented by all major containers. It is the in fact the first time when I can write components that are truly portable. But isn't it the time to define Common Dependency Injector?

By CDI I mean a set of classes, interfaces and rules that define how component should be written to enable dependencies to be injected no matter which container will be used. CDIP should include:
  • Universal container interface. Can be Common Service Locator for example
  • Some way to tell container if dependency is mandatory or not. Can be a custom attribute for example, like the one from Unity
  • One defined algorithm for choosing a constructor to be uses with constructor injection
  • One policy defining which dependencies are by default mandatory and which are not. For example, saying that constructor injection is mandatory and setter is not, or the opposite.

Nov 14, 2010 at 4:58 PM

Yep, the Common ServiceLocator is completely useless to me.  "Resolving" (aka GetInstance) is only 50% of what we do.  The other half is actually injecting things into a container at runtime.  Especially in plugable apps where you can't configure everything up-front in some config file or "bootstrapper".  Doing that takes too much time trying to coordinate with other developers to make sure EVERYTHING is injected properly.  So we do this in each module we develop.  So, I threw away the ServiceLocator and created my own "InjectionFactory", becuase let's face it, all their doing is creating a factory pattern here.  I went through and ported all these "Adapters" into my new model and it's working well.  I would post the code but, no one will care...

Dec 6, 2010 at 5:28 AM

CSL is not the uber replacement / abstraction for all containers. We deberately decided as a group NOT to support registration. The reasoning was that we felt it would force a common denominator approach that would end up being a leaky abstraction.

Instead the goal of CSL was to provide a common interface that a framework or application could use to grab implementations of a specific contract without being coupled to the container itself. It does do the job it was defined to do, i.e. provide services in a container agnostic fashion.