Interface Injector
-
- All Superinterfaces:
CandidateRegistry,InstanceResolver
- All Known Implementing Classes:
StandardInjector
public interface Injector extends CandidateRegistry, InstanceResolver
An injector is a combination of aCandidateRegistryand anInstanceResolver, 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.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description CandidateRegistrygetCandidateRegistry()Returns aCandidateRegistry, which can be shared instead of this class to share only methods that can be used to register and remove objects.InstanceResolvergetInstanceResolver()Returns anInstanceResolver, which can be shared instead of this class to share only methods that can be used to instantiate objects.-
Methods inherited from interface org.int4.dirk.api.CandidateRegistry
contains, register, register, registerInstance, remove, remove, removeInstance
-
Methods inherited from interface org.int4.dirk.api.InstanceResolver
getInstance, getInstance, getInstances, getInstances
-
-
-
-
Method Detail
-
getInstanceResolver
InstanceResolver getInstanceResolver()
Returns anInstanceResolver, which can be shared instead of this class to share only methods that can be used to instantiate objects.- Returns:
- an
InstanceResolver, nevernull
-
getCandidateRegistry
CandidateRegistry getCandidateRegistry()
Returns aCandidateRegistry, which can be shared instead of this class to share only methods that can be used to register and remove objects.- Returns:
- a
CandidateRegistry, nevernull
-
-