Class Injector

java.lang.Object
org.elasticsearch.injection.Injector

public final class Injector extends Object
The main object for dependency injection.

Allows the user to specify the requirements, then call inject(java.util.Collection<? extends java.lang.Class<?>>) to create an object plus all its dependencies.

Implementation note: this class itself contains logic for specifying the injection requirements; the actual injection operations are performed in other classes like Planner and PlanInterpreter,

  • Method Details

    • create

      public static Injector create()
    • addClass

      public Injector addClass(Class<?> classToProcess)
      Instructs the injector to instantiate classToProcess in accordance with whatever annotations may be present on that class.

      There are only three ways the injector can find out that it must instantiate some class:

      1. This method
      2. The parameter passed to inject(java.util.Collection<? extends java.lang.Class<?>>)
      3. A constructor parameter of some other class being instantiated, having exactly the right class (not a supertype)
      Returns:
      this
    • addClasses

      public Injector addClasses(Collection<Class<?>> classesToProcess)
      Equivalent to multiple chained calls to addClass(java.lang.Class<?>).
    • addInstance

      public <T> Injector addInstance(Object object)
    • addInstances

      public Injector addInstances(Collection<?> objects)
      Equivalent to multiple calls to addInstance(Object).
    • addInstance

      public <T> Injector addInstance(Class<? super T> type, T object)
      Indicates that object is to be injected for parameters of type type. The given object is treated as though it had been instantiated by the injector.
    • inject

      public Map<Class<?>,Object> inject(Collection<? extends Class<?>> resultTypes)
      Main entry point. Causes objects to be constructed.
      Returns:
      Map whose keys are all the requested resultTypes and whose values are all the instances of those types.