Injector (cayenne-doc: Cayenne Documentation 5.0-M2 API)
Description: declaration: package: org.apache.cayenne.di, interface: Injector

# Interface Injector

All Known Implementing Classes:
  `DefaultInjector`

public interface Injector
A facade to the Cayenne DI container. To create an injector use `DIBootstrap` static methods.

Since:
  3.1

- ## Method Summary

  Modifier and Type
  Method
  Description
  `<T> T`
  `getInstance(Class<T> type)`
  Returns a service instance bound in the container for a specific type.
  `<T> T`
  `getInstance(Key<T> key)`
  Returns a service instance bound in the container for a specific binding key.
  `<T> Provider<T>`
  `getProvider(Class<T> type)`
  `<T> Provider<T>`
  `getProvider(Key<T> key)`
  `void`
  `injectMembers(Object object)`
  Performs field injection on a given object, ignoring constructor injection.
  `void`
  `shutdown()`
  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. Throws `DIRuntimeException` if the type is not bound, or an instance can not be created.
    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> Provider<T> getProvider(Class<T> type) throws DIRuntimeException
    Throws:
      `DIRuntimeException`

  - ### getProvider

    <T> Provider<T> getProvider(Key<T> key) throws DIRuntimeException
    Throws:
      `DIRuntimeException`

  - ### injectMembers

    void injectMembers(Object object)
    Performs field injection on a given object, ignoring constructor injection. Since Cayenne DI injector returns fully injected objects, this method is rarely used directly.

    Note that using this method inside a custom DI `Provider` will most likely result in double injection, as 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.