Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Automatic) Dependency Injection Binding Mechanisms

The two common mechanisms for creating dependency injection bindings, such as through an IOC container, is from an XML configuration or a block of imperative code. In these cases, the key value pair is explicit (i.e. key = requested type, value = returned type).

Still, there is a third "heuristic" approach where an application/IOC container is given only [IMyClass] keys and the container then reflects over a set of application assembly dependencies to find all name-matched concrete classes [MyClass]. Said differently, the "return type" values are discovered rather than declared.

What I'd like to know is twofold:

  1. Which IOC containers (or other late-binding tools) permit the heuristic approach? Does this approach have a more common name?
  2. Are there other binding techniques, besides the three I've listed, which are used in practice?
like image 287
Brent Arias Avatar asked Oct 26 '11 07:10

Brent Arias


1 Answers

This is called Convention-based Configuration or Auto-registration and is supported by these .NET DI Containers:

  • Castle Windsor
  • StructureMap
  • Autofac

The most common configuration mechanisms used for DI Containers are

  • XML
  • Code as Configuration
  • Convention-based Configuration

A fourth, but uncommon, approach is to use attributes. The Managed Extensibility Framework is the most prominent example of this approach, which is more common in Java.

like image 114
Mark Seemann Avatar answered Nov 15 '22 16:11

Mark Seemann