Package com.google.inject.internal
Class InternalInjectorCreator
- java.lang.Object
-
- com.google.inject.internal.InternalInjectorCreator
-
public final class InternalInjectorCreator extends java.lang.Object
Builds a tree of injectors. This is a primary injector, plus child injectors needed for eachBinder.newPrivateBinder() private environment
. The primary injector is not necessarily a top-level injector.Injector construction happens in two phases.
- Static building. In this phase, we interpret commands, create bindings, and inspect dependencies. During this phase, we hold a lock to ensure consistency with parent injectors. No user code is executed in this phase.
- Dynamic injection. In this phase, we call user code. We inject members that requested
injection. This may require user's objects be created and their providers be called. And we
create eager singletons. In this phase, user code may have started other threads. This
phase is not executed for injectors created using
the tool stage
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
InternalInjectorCreator.ToolStageInjector
Injector
exposed to users inStage.TOOL
.
-
Field Summary
Fields Modifier and Type Field Description private ProcessedBindingData
bindingData
private Errors
errors
private Initializer
initializer
private InjectionRequestProcessor
injectionRequestProcessor
private InjectorShell.Builder
shellBuilder
private java.util.List<InjectorShell>
shells
private Stopwatch
stopwatch
-
Constructor Summary
Constructors Constructor Description InternalInjectorCreator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description InternalInjectorCreator
addModules(java.lang.Iterable<? extends Module> modules)
Injector
build()
private void
initializeStatically()
Initialize and validate everything.private void
injectDynamically()
Inject everything that can be injected.private boolean
isEagerSingleton(InjectorImpl injector, BindingImpl<?> binding, Stage stage)
(package private) void
loadEagerSingletons(InjectorImpl injector, Stage stage, Errors errors)
Loads eager singletons, or all singletons if we're in Stage.PRODUCTION.InternalInjectorCreator
parentInjector(InjectorImpl parent)
Sets the parent of the injector to-be-constructed.private Injector
primaryInjector()
Returns the injector being constructed.InternalInjectorCreator
stage(Stage stage)
-
-
-
Field Detail
-
stopwatch
private final Stopwatch stopwatch
-
errors
private final Errors errors
-
initializer
private final Initializer initializer
-
bindingData
private final ProcessedBindingData bindingData
-
injectionRequestProcessor
private final InjectionRequestProcessor injectionRequestProcessor
-
shellBuilder
private final InjectorShell.Builder shellBuilder
-
shells
private java.util.List<InjectorShell> shells
-
-
Method Detail
-
stage
public InternalInjectorCreator stage(Stage stage)
-
parentInjector
public InternalInjectorCreator parentInjector(InjectorImpl parent)
Sets the parent of the injector to-be-constructed. As a side effect, this sets this injector's stage to the stage ofparent
and sets#requireExplicitBindings()
if the parent injector also required them.
-
addModules
public InternalInjectorCreator addModules(java.lang.Iterable<? extends Module> modules)
-
build
public Injector build()
-
initializeStatically
private void initializeStatically()
Initialize and validate everything.
-
primaryInjector
private Injector primaryInjector()
Returns the injector being constructed. This is not necessarily the root injector.
-
injectDynamically
private void injectDynamically()
Inject everything that can be injected. This method is intentionally not synchronized. If we locked while injecting members (ie. running user code), things would deadlock should the user code build a just-in-time binding from another thread.
-
loadEagerSingletons
void loadEagerSingletons(InjectorImpl injector, Stage stage, Errors errors)
Loads eager singletons, or all singletons if we're in Stage.PRODUCTION. Bindings discovered while we're binding these singletons are not be eager.
-
isEagerSingleton
private boolean isEagerSingleton(InjectorImpl injector, BindingImpl<?> binding, Stage stage)
-
-