Dependency - Injector
The container injects dependencies when it creates the bean.
The injector's job is to assemble graphs of objects. You request an instance of a given type, and it figures out what to build, resolves dependencies, and wires everything together. To specify how dependencies are resolved, configure your injector.
Building object graphs by hand is labour intensive, error prone, and makes testing difficult. Instead, a container or dependency injector can build the object graph for you.
The dependency injector builds the object graph
Usually a dependency injector manages the lifecycle of objects and their dependencies based on a configuration file or annotations.
It can also allows to resolve dependencies at run time for extensibility using containers such as
- Windsor Castle - Inversion of Control container available for .NET and Silverlight,
- MEF (.NET Framework 4)
- https://github.com/google/guice/ - Guice is the first generic DI framework that takes advantage of Java annotations (type safe) as the main configuration mechanism. Example: Module and Presto example http
Dependency injection involves four elements:
- the implementation of a service object;
- the client object depending on the service;
- the interface the client uses to communicate with the service;
- and the injector object, which is responsible for injecting the service into the client. The injector object may also be referred to as an assembler, provider, container, factory, or spring
- http://weld.cdi-spec.org/ - Weld is the reference implementation of CDI for the Java
- https://dagger.dev/ - Dagger is a fully static, compile-time dependency injection framework for both Java and Android.
JSR-330 (javax.inject) - Dependency Injection for Java
JSR-330 standardizes annotations like @Inject and the Provider interfaces for Java platforms.