Interface Injector

  • All Superinterfaces:
    CandidateRegistry, InstanceResolver
    All Known Implementing Classes:
    StandardInjector

    public interface Injector
    extends CandidateRegistry, InstanceResolver
    An injector is a combination of a CandidateRegistry and an InstanceResolver, providing the functionality of both interfaces in a single type.

    An injector provides instances of classes or interfaces which have been registered with it or which can be auto discovered (if enabled). Each instance returned is injected with further dependencies if any of its fields or constructors are annotated with an inject annotation.

    The potential candidates for injection can be registered with the injector in various ways, for example by providing classes or existing instances. In order to successfully register a type, all its dependencies must be met as well, and all dependencies it provides must not conflict with any types already registered. If a conflict or cycle is detected during registration, an exception will be thrown.

    For example, consider an injector for which a class A and B are registered and where class A has a field that requires an instance of class B. Any of the following actions will throw an exception:

    • Removing class B; this would make construction of A impossible as B is a requirement.
    • Registering a subclass of B; this would make construction of A ambiguous as there are two possible candidates for the required B.
    • Registering a class which either provides or produces instances of B (or a subclass); again this would make construction of A ambiguous.