Package com.google.inject.internal
Class InternalContext
java.lang.Object
com.google.inject.internal.InternalContext
- All Implemented Interfaces:
AutoCloseable
Internal context. Used to coordinate injections and support circular dependencies.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<Object,
ConstructionContext<?>> private Dependency<?>
Keeps track of the type that is currently being requested for injection.private Object[]
Keeps track of the hierarchy of types needed during injection.private int
private int
The number of timesenter()
has been called + 1 for initial construction.private final InjectorImpl.InjectorOptions
private final Object[]
A single element array to clear when theenterCount
hits0
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Should be called any any method that received an instance via InjectorImpl.enterContext().private void
doPushState
(Object dependencyOrKey, Object source) (package private) void
enter()
Should only be called by InjectorImpl.enterContext().(package private) <T> ConstructionContext<T>
(package private) Dependency<?>
(package private) List<DependencyAndSource>
Returns the current dependency chain (all the state stored in the dependencyStack).(package private) InjectorImpl.InjectorOptions
(package private) void
popState()
Pops from the state without setting a dependency.(package private) void
popStateAndSetDependency
(Dependency<?> newDependency) Pops the current state & sets the new dependency.(package private) Dependency<?>
pushDependency
(Dependency<?> dependency, Object source) Sets the new current dependency & adds it to the state.(package private) void
Adds to the state without setting the dependency.
-
Field Details
-
options
-
constructionContexts
-
dependency
Keeps track of the type that is currently being requested for injection. -
dependencyStack
Keeps track of the hierarchy of types needed during injection.This is a pairwise combination of dependencies and sources, with dependencies or keys on even indices, and sources on odd indices. This structure is to avoid the memory overhead of DependencyAndSource objects, which can add to several tens of megabytes in large applications.
-
dependencyStackSize
private int dependencyStackSize -
enterCount
private int enterCountThe number of timesenter()
has been called + 1 for initial construction. This value is decremented when#exit()
is called. -
toClear
A single element array to clear when theenterCount
hits0
.This is the value stored in the
InjectorImpl.localContext
thread local.
-
-
Constructor Details
-
InternalContext
InternalContext(InjectorImpl.InjectorOptions options, Object[] toClear)
-
-
Method Details
-
enter
void enter()Should only be called by InjectorImpl.enterContext(). -
close
public void close()Should be called any any method that received an instance via InjectorImpl.enterContext().- Specified by:
close
in interfaceAutoCloseable
-
getInjectorOptions
InjectorImpl.InjectorOptions getInjectorOptions() -
getConstructionContext
-
getDependency
Dependency<?> getDependency() -
pushDependency
Sets the new current dependency & adds it to the state. -
popStateAndSetDependency
Pops the current state & sets the new dependency. -
pushState
Adds to the state without setting the dependency. -
doPushState
-
popState
void popState()Pops from the state without setting a dependency. -
getDependencyChain
List<DependencyAndSource> getDependencyChain()Returns the current dependency chain (all the state stored in the dependencyStack).
-