public class DependencyInjector
extends java.lang.Object
Class that allows manages the dependency injection in the system. This class is mainly sued to inject dependencies in JavaFX controllers through the controllers factory.
Calling inject(Object)
will inject values in the fields
of the given object that are annotated with the annotation passed to the constructor
resolving those values from the sources added through
addDependencyResolver(DependencySource)
.
DependencySource
Constructor and Description |
---|
DependencyInjector(java.lang.Class<? extends java.lang.annotation.Annotation> injectionAnnotation,
boolean ignoreMissingDependencies) |
Modifier and Type | Method and Description |
---|---|
void |
addDependencyResolver(DependencySource source)
Add a source to resolve dependencies from.
When trying to resolve a dependency and that a cache-miss happens, the sources are inspected in the same order as they were added to the dependency injection system through this method. |
void |
disableCache()
Disables cache access.
|
void |
enableCache()
Enables cache access.
|
void |
inject(java.lang.Object injectionTarget)
Injects dependencies in the given object.
This fields annotated with InjectValue then
tries to find a value that fits the type. |
public DependencyInjector(java.lang.Class<? extends java.lang.annotation.Annotation> injectionAnnotation, boolean ignoreMissingDependencies)
public void enableCache()
Cache is enabled by default.
disableCache()
public void disableCache()
public void addDependencyResolver(DependencySource source)
source
- an instance of a class providing dependencies valuespublic void inject(java.lang.Object injectionTarget)
InjectValue
then
tries to find a value that fits the type. If no value
can be found be to injected, a IllegalStateException
is thrown.injectionTarget
- the object to inject dependencies to