Class DefaultInjector

java.lang.Object
io.bootique.di.spi.DefaultInjector
All Implemented Interfaces:
Injector

public class DefaultInjector extends Object implements Injector
A default implementations of a DI injector.
  • Constructor Details

  • Method Details

    • getInstance

      public <T> T getInstance(Class<T> type)
      Description copied from interface: Injector
      Returns a service instance bound in the container for a specific type. If the type is not explicitly bound to an implementation, a provider, or a provider method, tries to create an object of this type on the fly. In that case, if an object can not be created by the Injector (e.g. if it is an interface), throws DIRuntimeException.
      Specified by:
      getInstance in interface Injector
    • getInstance

      public <T> T getInstance(Key<T> key)
      Description copied from interface: Injector
      Returns a service instance bound in the container for a specific binding key. Throws DIRuntimeException if the key is not bound, or an instance can not be created.
      Specified by:
      getInstance in interface Injector
    • getProvider

      public <T> javax.inject.Provider<T> getProvider(Class<T> type)
      Specified by:
      getProvider in interface Injector
    • getProvider

      public <T> javax.inject.Provider<T> getProvider(Key<T> key)
      Specified by:
      getProvider in interface Injector
    • hasProvider

      public boolean hasProvider(Class<?> type)
      Specified by:
      hasProvider in interface Injector
      Parameters:
      type - binding type to check
      Returns:
      is provider for given type registered
    • hasProvider

      public boolean hasProvider(Key<?> key)
      Specified by:
      hasProvider in interface Injector
      Parameters:
      key - binding key to check
      Returns:
      is provider for given key registered
    • injectMembers

      public void injectMembers(Object object)
      Description copied from interface: Injector
      Performs field injection on a given object, ignoring constructor injection. This method is rarely used directly, as objects that require dependency injection are usually themselves obtained from the injector, and have all their fields already initialized.

      Using this method inside a custom Provider will most likely result in double injection, as each custom provider is wrapped in a field-injecting provider by the DI container. Instead, custom providers must initialize object properties manually, obtaining dependencies from Injector.

      Specified by:
      injectMembers in interface Injector
    • shutdown

      public void shutdown()
      Description copied from interface: Injector
      A lifecycle method that let's the injector's services to clean up their state and release resources. This method would normally generate a scope end event for the injector's one and only singleton scope.
      Specified by:
      shutdown in interface Injector
    • getKeysByType

      public <T> Collection<Key<T>> getKeysByType(Class<T> type)
      Description copied from interface: Injector
      Returns collection of Key bound to given type, regardless of additional qualifiers (annotations and/or names).
      Specified by:
      getKeysByType in interface Injector
      Type Parameters:
      T - type
      Parameters:
      type - interested class object
      Returns:
      collection of keys bound to given type