Interface Injector

All Known Implementing Classes:
DefaultInjector

public interface Injector
A facade to the Bootique DI container. To create an injector use DIBootstrap static methods.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    getInstance(Key<T> key)
    Returns a service instance bound in the container for a specific binding key.
    <T> T
    getInstance(Class<T> type)
    Returns a service instance bound in the container for a specific type.
    <T> Collection<Key<T>>
    Returns collection of Key bound to given type, regardless of additional qualifiers (annotations and/or names).
    <T> javax.inject.Provider<T>
    getProvider(Key<T> key)
     
    <T> javax.inject.Provider<T>
    getProvider(Class<T> type)
     
    boolean
    hasProvider(Key<?> key)
     
    boolean
    hasProvider(Class<?> type)
     
    void
    Performs field injection on a given object, ignoring constructor injection.
    void
    A lifecycle method that let's the injector's services to clean up their state and release resources.
  • Method Details

    • getInstance

      <T> T getInstance(Class<T> type) throws DIRuntimeException
      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.
      Throws:
      DIRuntimeException
    • getInstance

      <T> T getInstance(Key<T> key) throws DIRuntimeException
      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.
      Throws:
      DIRuntimeException
    • getProvider

      <T> javax.inject.Provider<T> getProvider(Class<T> type) throws DIRuntimeException
      Throws:
      DIRuntimeException
    • getProvider

      <T> javax.inject.Provider<T> getProvider(Key<T> key) throws DIRuntimeException
      Throws:
      DIRuntimeException
    • hasProvider

      boolean hasProvider(Class<?> type) throws DIRuntimeException
      Parameters:
      type - binding type to check
      Returns:
      is provider for given type registered
      Throws:
      DIRuntimeException
    • hasProvider

      boolean hasProvider(Key<?> key) throws DIRuntimeException
      Parameters:
      key - binding key to check
      Returns:
      is provider for given key registered
      Throws:
      DIRuntimeException
    • injectMembers

      void injectMembers(Object object)
      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.

    • shutdown

      void shutdown()
      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.
    • getKeysByType

      <T> Collection<Key<T>> getKeysByType(Class<T> type)
      Returns collection of Key bound to given type, regardless of additional qualifiers (annotations and/or names).
      Type Parameters:
      T - type
      Parameters:
      type - interested class object
      Returns:
      collection of keys bound to given type