Package com.google.inject.internal
Class Initializer
java.lang.Object
com.google.inject.internal.Initializer
Manages and injects instances at injector-creation time. This is made more complicated by
instances that request other instances while they're being injected. We overcome this by using
Initializable
, which attempts to perform injection before use.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private static enum
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final CycleDetectingLock.CycleDetectingLockFactory
<Class<?>> Allows us to detect circular dependencies.private final IdentityHashMap
<Object, Initializer.InjectableReference<?>> Map that guarantees that no instance would get two references.private final List
<Initializer.InjectableReference<?>> Instances that need injection during injector creation to a source that registered them.private boolean
Is set to true oncevalidateOustandingInjections(com.google.inject.internal.Errors)
is called. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) void
Performs creation-time injections on all objects that require it.(package private) <T> Initializable
<T> requestInjection
(InjectorImpl injector, T instance, Binding<T> binding, Object source, Set<InjectionPoint> injectionPoints) Registers an instance for member injection when that step is performed.(package private) void
validateOustandingInjections
(Errors errors) Prepares member injectors for all injected instances.
-
Field Details
-
validationStarted
private volatile boolean validationStartedIs set to true oncevalidateOustandingInjections(com.google.inject.internal.Errors)
is called. -
cycleDetectingLockFactory
Allows us to detect circular dependencies. It's only used during injectable reference initialization. After initialization direct access through volatile field is used. -
pendingInjections
Instances that need injection during injector creation to a source that registered them. New references added beforevalidateOustandingInjections(com.google.inject.internal.Errors)
. Cleared up ininjectAll(com.google.inject.internal.Errors)
. -
initializablesCache
Map that guarantees that no instance would get two references. New references added beforevalidateOustandingInjections(com.google.inject.internal.Errors)
. Cleared up invalidateOustandingInjections(com.google.inject.internal.Errors)
.
-
-
Constructor Details
-
Initializer
Initializer()
-
-
Method Details
-
requestInjection
<T> Initializable<T> requestInjection(InjectorImpl injector, T instance, Binding<T> binding, Object source, Set<InjectionPoint> injectionPoints) Registers an instance for member injection when that step is performed.- Parameters:
instance
- an instance that optionally has members to be injected (each annotated with @Inject).binding
- the binding that caused this initializable to be created, if it exists.source
- the source location that this injection was requested
-
validateOustandingInjections
Prepares member injectors for all injected instances. This prompts Guice to do static analysis on the injected instances. -
injectAll
Performs creation-time injections on all objects that require it. Whenever fulfilling an injection depends on another object that requires injection, we inject it first. If the two instances are codependent (directly or transitively), ordering of injection is arbitrary.
-