Class InjectorImpl
- java.lang.Object
-
- com.google.inject.internal.InjectorImpl
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
InjectorImpl.ConvertedConstantBindingImpl<T>
(package private) static class
InjectorImpl.InjectorOptions
Options that control how the injector behaves.(package private) static class
InjectorImpl.JitLimitation
some limitations on what just in time bindings are allowed.(package private) static interface
InjectorImpl.MethodInvoker
Invokes a method.private static class
InjectorImpl.SyntheticProviderBindingImpl<T>
A framework-created JIT Providerbinding.
-
Field Summary
Fields Modifier and Type Field Description (package private) com.google.common.collect.ListMultimap<TypeLiteral<?>,Binding<?>>
bindingsMultimap
(package private) ConstructorInjectorStore
constructors
Cached constructor injectors for each type(package private) java.util.Set<Key<?>>
failedJitBindings
Cache of Keys that we were unable to create JIT bindings for, so we don't keep trying.(package private) java.util.Map<Key<?>,BindingImpl<?>>
jitBindings
Just-in-time binding cache.private java.lang.ThreadLocal<java.lang.Object[]>
localContext
Holds Object[] as a mutable wrapper, rather than InternalContext, since array operations are faster than ThreadLocal.set() / .get() operations.(package private) Lookups
lookups
(package private) MembersInjectorStore
membersInjectorStore
Cached field and method injectors for each type.(package private) InjectorImpl.InjectorOptions
options
(package private) InjectorImpl
parent
(package private) ProvisionListenerCallbackStore
provisionListenerStore
Cached provision listener callbacks for each key.(package private) State
state
static TypeLiteral<java.lang.String>
STRING_TYPE
(package private) java.util.Set<TypeLiteral<?>>
userRequestedMembersInjectorTypes
The set of types passed togetMembersInjector(com.google.inject.TypeLiteral<T>)
andinjectMembers(java.lang.Object)
.
-
Constructor Summary
Constructors Constructor Description InjectorImpl(InjectorImpl parent, State state, InjectorImpl.InjectorOptions injectorOptions)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
cleanup(BindingImpl<?> binding, java.util.Set<Key> encountered)
Iterates through the binding's dependencies to clean up any stray bindings that were leftover from a failed JIT binding.private <T> BindingImpl<T>
convertConstantStringBinding(Key<T> key, Errors errors)
Converts a constant string binding to the required type.Injector
createChildInjector(Module... modules)
Returns a new injector that inherits all state from this injector.Injector
createChildInjector(java.lang.Iterable<? extends Module> modules)
Returns a new injector that inherits all state from this injector.private <T> BindingImpl<T>
createImplementedByBinding(Key<T> key, Scoping scoping, ImplementedBy implementedBy, Errors errors)
Creates a binding for a type annotated with @ImplementedBy.private <T> BindingImpl<T>
createJustInTimeBinding(Key<T> key, Errors errors, boolean jitDisabled, InjectorImpl.JitLimitation jitType)
Returns a new just-in-time binding created by resolvingkey
.private <T> BindingImpl<T>
createJustInTimeBindingRecursive(Key<T> key, Errors errors, boolean jitDisabled, InjectorImpl.JitLimitation jitType)
Attempts to create a just-in-time binding forkey
in the root injector, falling back to other ancestor injectors until this injector is tried.private <T> BindingImpl<MembersInjector<T>>
createMembersInjectorBinding(Key<MembersInjector<T>> key, Errors errors)
(package private) <T> SingleParameterInjector<T>
createParameterInjector(Dependency<T> dependency, Errors errors)
(package private) <T> BindingImpl<T>
createProvidedByBinding(Key<T> key, Scoping scoping, ProvidedBy providedBy, Errors errors)
Creates a binding for a type annotated with @ProvidedBy.private <T> BindingImpl<Provider<T>>
createSyntheticProviderBinding(Key<Provider<T>> key, Errors errors)
Creates a synthetic binding toProvider<T>
, i.e.private <T> BindingImpl<TypeLiteral<T>>
createTypeLiteralBinding(Key<TypeLiteral<T>> key, Errors errors)
Converts a binding for aKey<TypeLiteral<T>>
to the valueTypeLiteral<T>
.(package private) <T> BindingImpl<T>
createUninitializedBinding(Key<T> key, Scoping scoping, java.lang.Object source, Errors errors, boolean jitBinding)
Creates a binding for an injectable type with the given scope.(package private) InternalContext
enterContext()
Looks up thread local context andenters
it or creates a new context if necessary.<T> java.util.List<Binding<T>>
findBindingsByType(TypeLiteral<T> type)
Returns all explicit bindings fortype
.java.util.Map<Key<?>,Binding<?>>
getAllBindings()
Returns a snapshot of this injector's bindings, both explicit and just-in-time.java.util.Map<TypeLiteral<?>,java.util.List<InjectionPoint>>
getAllMembersInjectorInjectionPoints()
Returns the injection points created for calls toInjector.getMembersInjector(com.google.inject.TypeLiteral<T>)
(either directly or indirectly, e.g.<T> BindingImpl<T>
getBinding(Key<T> key)
Returns the binding forkey
<T> Binding<T>
getBinding(java.lang.Class<T> type)
Returns the binding for the given type.(package private) <T> BindingImpl<T>
getBindingOrThrow(Key<T> key, Errors errors, InjectorImpl.JitLimitation jitType)
Gets a binding implementation.java.util.Map<Key<?>,Binding<?>>
getBindings()
Returns this injector's explicit bindings.java.util.List<Element>
getElements()
Returns the elements that make up this injector.<T> BindingImpl<T>
getExistingBinding(Key<T> key)
Returns the binding if it already exists, or null if does not exist.<T> T
getInstance(Key<T> key)
Returns the appropriate instance for the given injection key; equivalent togetProvider(key).get()
.<T> T
getInstance(java.lang.Class<T> type)
Returns the appropriate instance for the given injection type; equivalent togetProvider(type).get()
.private java.util.Set<Dependency<?>>
getInternalDependencies(BindingImpl<?> binding)
Safely gets the dependencies of possibly not initialized bindings.(package private) <T> InternalFactory<? extends T>
getInternalFactory(Key<T> key, Errors errors, InjectorImpl.JitLimitation jitType)
private <T> BindingImpl<T>
getJustInTimeBinding(Key<T> key, Errors errors, InjectorImpl.JitLimitation jitType)
Returns a just-in-time binding forkey
, creating it if necessary.(package private) InternalContext
getLocalContext()
Only to be called by theSingletonScope
provider.<T> MembersInjector<T>
getMembersInjector(TypeLiteral<T> typeLiteral)
Returns the members injector used to inject dependencies into methods and fields on instances of the given typeT
.<T> MembersInjector<T>
getMembersInjector(java.lang.Class<T> type)
Returns the members injector used to inject dependencies into methods and fields on instances of the given typeT
.(package private) SingleParameterInjector<?>[]
getParametersInjectors(java.util.List<Dependency<?>> parameters, Errors errors)
Returns parameter injectors, ornull
if there are no parameters.Injector
getParent()
Returns this injector's parent, ornull
if this is a top-level injector.private static <T> Key<T>
getProvidedKey(Key<Provider<T>> key, Errors errors)
<T> Provider<T>
getProvider(Key<T> key)
Returns the provider used to obtain instances for the given injection key.<T> Provider<T>
getProvider(java.lang.Class<T> type)
Returns the provider used to obtain instances for the given type.(package private) <T> Provider<T>
getProviderOrThrow(Dependency<T> dependency, Errors errors)
java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,Scope>
getScopeBindings()
Returns a map containing all scopes in the injector.java.util.Set<TypeConverterBinding>
getTypeConverterBindings()
Returns a set containing all type converter bindings in the injector.(package private) void
index()
Indexes bindings by type.(package private) <T> void
initializeBinding(BindingImpl<T> binding, Errors errors)
(package private) <T> void
initializeJitBinding(BindingImpl<T> binding, Errors errors)
void
injectMembers(java.lang.Object instance)
Injects dependencies into the fields and methods ofinstance
.private static boolean
isMembersInjector(Key<?> key)
Returns true if the key type is MembersInjector (but not a subclass of MembersInjector).private static boolean
isProvider(Key<?> key)
Returns true if the key type is Provider (but not a subclass of Provider).private static boolean
isTypeLiteral(Key<?> key)
private void
removeFailedJitBinding(Binding<?> binding, InjectionPoint ip)
Cleans up any state that may have been cached when constructing the JIT binding.java.lang.String
toString()
-
-
-
Field Detail
-
STRING_TYPE
public static final TypeLiteral<java.lang.String> STRING_TYPE
-
state
final State state
-
parent
final InjectorImpl parent
-
bindingsMultimap
final com.google.common.collect.ListMultimap<TypeLiteral<?>,Binding<?>> bindingsMultimap
-
options
final InjectorImpl.InjectorOptions options
-
jitBindings
final java.util.Map<Key<?>,BindingImpl<?>> jitBindings
Just-in-time binding cache. Guarded by state.lock()
-
failedJitBindings
final java.util.Set<Key<?>> failedJitBindings
Cache of Keys that we were unable to create JIT bindings for, so we don't keep trying. Also guarded by state.lock().
-
lookups
Lookups lookups
-
userRequestedMembersInjectorTypes
final java.util.Set<TypeLiteral<?>> userRequestedMembersInjectorTypes
The set of types passed togetMembersInjector(com.google.inject.TypeLiteral<T>)
andinjectMembers(java.lang.Object)
.
-
constructors
final ConstructorInjectorStore constructors
Cached constructor injectors for each type
-
membersInjectorStore
MembersInjectorStore membersInjectorStore
Cached field and method injectors for each type.
-
provisionListenerStore
ProvisionListenerCallbackStore provisionListenerStore
Cached provision listener callbacks for each key.
-
localContext
private final java.lang.ThreadLocal<java.lang.Object[]> localContext
Holds Object[] as a mutable wrapper, rather than InternalContext, since array operations are faster than ThreadLocal.set() / .get() operations.Holds Object[] rather than InternalContext[], since localContext never gets cleaned up at any point. This could lead to problems when, for example, an OSGI application is reloaded, the InjectorImpl is destroyed, but the thread that the injector runs on is kept alive. In such a case, ThreadLocal itself would hold on to a reference to localContext, which would hold on to the old InternalContext.class object, which would hold on to the old classloader that loaded that class, and so on.
-
-
Constructor Detail
-
InjectorImpl
InjectorImpl(InjectorImpl parent, State state, InjectorImpl.InjectorOptions injectorOptions)
-
-
Method Detail
-
index
void index()
Indexes bindings by type.
-
findBindingsByType
public <T> java.util.List<Binding<T>> findBindingsByType(TypeLiteral<T> type)
Description copied from interface:Injector
Returns all explicit bindings fortype
.This method is part of the Guice SPI and is intended for use by tools and extensions.
- Specified by:
findBindingsByType
in interfaceInjector
-
getBinding
public <T> BindingImpl<T> getBinding(Key<T> key)
Returns the binding forkey
- Specified by:
getBinding
in interfaceInjector
-
getExistingBinding
public <T> BindingImpl<T> getExistingBinding(Key<T> key)
Description copied from interface:Injector
Returns the binding if it already exists, or null if does not exist. UnlikeInjector.getBinding(Key)
, this does not attempt to create just-in-time bindings for keys that aren't bound.This method is part of the Guice SPI and is intended for use by tools and extensions.
- Specified by:
getExistingBinding
in interfaceInjector
-
getBindingOrThrow
<T> BindingImpl<T> getBindingOrThrow(Key<T> key, Errors errors, InjectorImpl.JitLimitation jitType) throws ErrorsException
Gets a binding implementation. First, it check to see if the parent has a binding. If the parent has a binding and the binding is scoped, it will use that binding. Otherwise, this checks for an explicit binding. If no explicit binding is found, it looks for a just-in-time binding.- Throws:
ErrorsException
-
getBinding
public <T> Binding<T> getBinding(java.lang.Class<T> type)
Description copied from interface:Injector
Returns the binding for the given type. This will be an explicit bindings if the injection key was bound explicitly by a module, or an implicit binding otherwise. The implicit binding will be created if necessary.This method is part of the Guice SPI and is intended for use by tools and extensions.
- Specified by:
getBinding
in interfaceInjector
-
getParent
public Injector getParent()
Description copied from interface:Injector
Returns this injector's parent, ornull
if this is a top-level injector.
-
createChildInjector
public Injector createChildInjector(java.lang.Iterable<? extends Module> modules)
Description copied from interface:Injector
Returns a new injector that inherits all state from this injector. All bindings, scopes, interceptors and type converters are inherited -- they are visible to the child injector. Elements of the child injector are not visible to its parent.Just-in-time bindings created for child injectors will be created in an ancestor injector whenever possible. This allows for scoped instances to be shared between injectors. Use explicit bindings to prevent bindings from being shared with the parent injector. Optional injections in just-in-time bindings (created in the parent injector) may be silently ignored if the optional dependencies are from the child injector.
No key may be bound by both an injector and one of its ancestors. This includes just-in-time bindings. The lone exception is the key for
Injector.class
, which is bound by each injector to itself.- Specified by:
createChildInjector
in interfaceInjector
-
createChildInjector
public Injector createChildInjector(Module... modules)
Description copied from interface:Injector
Returns a new injector that inherits all state from this injector. All bindings, scopes, interceptors and type converters are inherited -- they are visible to the child injector. Elements of the child injector are not visible to its parent.Just-in-time bindings created for child injectors will be created in an ancestor injector whenever possible. This allows for scoped instances to be shared between injectors. Use explicit bindings to prevent bindings from being shared with the parent injector.
No key may be bound by both an injector and one of its ancestors. This includes just-in-time bindings. The lone exception is the key for
Injector.class
, which is bound by each injector to itself.- Specified by:
createChildInjector
in interfaceInjector
-
getJustInTimeBinding
private <T> BindingImpl<T> getJustInTimeBinding(Key<T> key, Errors errors, InjectorImpl.JitLimitation jitType) throws ErrorsException
Returns a just-in-time binding forkey
, creating it if necessary.- Throws:
ErrorsException
- if the binding could not be created.
-
isProvider
private static boolean isProvider(Key<?> key)
Returns true if the key type is Provider (but not a subclass of Provider).
-
isTypeLiteral
private static boolean isTypeLiteral(Key<?> key)
-
getProvidedKey
private static <T> Key<T> getProvidedKey(Key<Provider<T>> key, Errors errors) throws ErrorsException
- Throws:
ErrorsException
-
isMembersInjector
private static boolean isMembersInjector(Key<?> key)
Returns true if the key type is MembersInjector (but not a subclass of MembersInjector).
-
createMembersInjectorBinding
private <T> BindingImpl<MembersInjector<T>> createMembersInjectorBinding(Key<MembersInjector<T>> key, Errors errors) throws ErrorsException
- Throws:
ErrorsException
-
createSyntheticProviderBinding
private <T> BindingImpl<Provider<T>> createSyntheticProviderBinding(Key<Provider<T>> key, Errors errors) throws ErrorsException
Creates a synthetic binding toProvider<T>
, i.e. a framework-created JIT binding to the provider fromBinding<T>
.- Throws:
ErrorsException
-
convertConstantStringBinding
private <T> BindingImpl<T> convertConstantStringBinding(Key<T> key, Errors errors) throws ErrorsException
Converts a constant string binding to the required type.- Returns:
- the binding if it could be resolved, or null if the binding doesn't exist
- Throws:
ErrorsException
- if there was an error resolving the binding
-
initializeBinding
<T> void initializeBinding(BindingImpl<T> binding, Errors errors) throws ErrorsException
- Throws:
ErrorsException
-
initializeJitBinding
<T> void initializeJitBinding(BindingImpl<T> binding, Errors errors) throws ErrorsException
- Throws:
ErrorsException
-
cleanup
private boolean cleanup(BindingImpl<?> binding, java.util.Set<Key> encountered)
Iterates through the binding's dependencies to clean up any stray bindings that were leftover from a failed JIT binding. This is required because the bindings are eagerly & optimistically added to allow circular dependency support, so dependencies may pass where they should have failed.
-
removeFailedJitBinding
private void removeFailedJitBinding(Binding<?> binding, InjectionPoint ip)
Cleans up any state that may have been cached when constructing the JIT binding.
-
getInternalDependencies
private java.util.Set<Dependency<?>> getInternalDependencies(BindingImpl<?> binding)
Safely gets the dependencies of possibly not initialized bindings.
-
createUninitializedBinding
<T> BindingImpl<T> createUninitializedBinding(Key<T> key, Scoping scoping, java.lang.Object source, Errors errors, boolean jitBinding) throws ErrorsException
Creates a binding for an injectable type with the given scope. Looks for a scope on the type if none is specified.- Throws:
ErrorsException
-
createTypeLiteralBinding
private <T> BindingImpl<TypeLiteral<T>> createTypeLiteralBinding(Key<TypeLiteral<T>> key, Errors errors) throws ErrorsException
Converts a binding for aKey<TypeLiteral<T>>
to the valueTypeLiteral<T>
. It's a bit awkward because we have to pull out the inner type in the type literal.- Throws:
ErrorsException
-
createProvidedByBinding
<T> BindingImpl<T> createProvidedByBinding(Key<T> key, Scoping scoping, ProvidedBy providedBy, Errors errors) throws ErrorsException
Creates a binding for a type annotated with @ProvidedBy.- Throws:
ErrorsException
-
createImplementedByBinding
private <T> BindingImpl<T> createImplementedByBinding(Key<T> key, Scoping scoping, ImplementedBy implementedBy, Errors errors) throws ErrorsException
Creates a binding for a type annotated with @ImplementedBy.- Throws:
ErrorsException
-
createJustInTimeBindingRecursive
private <T> BindingImpl<T> createJustInTimeBindingRecursive(Key<T> key, Errors errors, boolean jitDisabled, InjectorImpl.JitLimitation jitType) throws ErrorsException
Attempts to create a just-in-time binding forkey
in the root injector, falling back to other ancestor injectors until this injector is tried.- Throws:
ErrorsException
-
createJustInTimeBinding
private <T> BindingImpl<T> createJustInTimeBinding(Key<T> key, Errors errors, boolean jitDisabled, InjectorImpl.JitLimitation jitType) throws ErrorsException
Returns a new just-in-time binding created by resolvingkey
. The strategies used to create just-in-time bindings are:- Internalizing Providers. If the requested binding is for
Provider<T>
, we delegate to the binding forT
. - Converting constants.
- ImplementedBy and ProvidedBy annotations. Only for unannotated keys.
- The constructor of the raw type. Only for unannotated keys.
- Throws:
ErrorsException
- if the binding cannot be created.
- Internalizing Providers. If the requested binding is for
-
getInternalFactory
<T> InternalFactory<? extends T> getInternalFactory(Key<T> key, Errors errors, InjectorImpl.JitLimitation jitType) throws ErrorsException
- Throws:
ErrorsException
-
getBindings
public java.util.Map<Key<?>,Binding<?>> getBindings()
Description copied from interface:Injector
Returns this injector's explicit bindings.The returned map does not include bindings inherited from a
parent injector
, should one exist. The returned map is guaranteed to iterate (for example, with itsMap.entrySet()
iterator) in the order of insertion. In other words, the order in which bindings appear in user Modules.This method is part of the Guice SPI and is intended for use by tools and extensions.
- Specified by:
getBindings
in interfaceInjector
-
getAllBindings
public java.util.Map<Key<?>,Binding<?>> getAllBindings()
Description copied from interface:Injector
Returns a snapshot of this injector's bindings, both explicit and just-in-time. The returned map is immutable; it contains only the bindings that were present whengetAllBindings()
was invoked. Just-in-time bindings are only present if they have been requested at least once. Subsequent calls may return a map with additional just-in-time bindings.The returned map does not include bindings inherited from a
parent injector
, should one exist.This method is part of the Guice SPI and is intended for use by tools and extensions.
- Specified by:
getAllBindings
in interfaceInjector
-
getScopeBindings
public java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,Scope> getScopeBindings()
Description copied from interface:Injector
Returns a map containing all scopes in the injector. The maps keys are scoping annotations likeSingleton.class
, and the values are scope instances, such asScopes.SINGLETON
. The returned map is immutable.This method is part of the Guice SPI and is intended for use by tools and extensions.
- Specified by:
getScopeBindings
in interfaceInjector
-
getTypeConverterBindings
public java.util.Set<TypeConverterBinding> getTypeConverterBindings()
Description copied from interface:Injector
Returns a set containing all type converter bindings in the injector. The returned set is immutable.This method is part of the Guice SPI and is intended for use by tools and extensions.
- Specified by:
getTypeConverterBindings
in interfaceInjector
-
getElements
public java.util.List<Element> getElements()
Description copied from interface:Injector
Returns the elements that make up this injector. Note that not all kinds of elements are returned.The returned list does not include elements inherited from a
parent injector
, should one exist.The returned list is immutable; it contains only the elements that were present when
Injector.getElements()
was invoked. Subsequent calls may return a list with additional elements.The returned list does not include data inherited from a
parent injector
, should one exist.This method is part of the Guice SPI and is intended for use by tools and extensions.
- Specified by:
getElements
in interfaceInjector
-
getAllMembersInjectorInjectionPoints
public java.util.Map<TypeLiteral<?>,java.util.List<InjectionPoint>> getAllMembersInjectorInjectionPoints()
Description copied from interface:Injector
Returns the injection points created for calls toInjector.getMembersInjector(com.google.inject.TypeLiteral<T>)
(either directly or indirectly, e.g. throughInjector.injectMembers(java.lang.Object)
.This excludes any injection points from elements (which are accessible from each element via the SPI), unless
Injector.getMembersInjector(com.google.inject.TypeLiteral<T>)
orInjector.injectMembers(java.lang.Object)
were also called for the same key.The returned multimap does not include data inherited from a
parent injector
, should one exist.This method is part of the Guice SPI and is intended for use by tools and extensions.
- Specified by:
getAllMembersInjectorInjectionPoints
in interfaceInjector
-
getParametersInjectors
SingleParameterInjector<?>[] getParametersInjectors(java.util.List<Dependency<?>> parameters, Errors errors) throws ErrorsException
Returns parameter injectors, ornull
if there are no parameters.- Throws:
ErrorsException
-
createParameterInjector
<T> SingleParameterInjector<T> createParameterInjector(Dependency<T> dependency, Errors errors) throws ErrorsException
- Throws:
ErrorsException
-
injectMembers
public void injectMembers(java.lang.Object instance)
Description copied from interface:Injector
Injects dependencies into the fields and methods ofinstance
. Ignores the presence or absence of an injectable constructor.Whenever Guice creates an instance, it performs this injection automatically (after first performing constructor injection), so if you're able to let Guice create all your objects for you, you'll never need to use this method.
- Specified by:
injectMembers
in interfaceInjector
- Parameters:
instance
- to inject members on- See Also:
for a preferred alternative that supports checks before run time
-
getMembersInjector
public <T> MembersInjector<T> getMembersInjector(TypeLiteral<T> typeLiteral)
Description copied from interface:Injector
Returns the members injector used to inject dependencies into methods and fields on instances of the given typeT
.- Specified by:
getMembersInjector
in interfaceInjector
- Specified by:
getMembersInjector
in interfaceLookups
- Parameters:
typeLiteral
- type to get members injector for- See Also:
for an alternative that offers up front error detection
-
getMembersInjector
public <T> MembersInjector<T> getMembersInjector(java.lang.Class<T> type)
Description copied from interface:Injector
Returns the members injector used to inject dependencies into methods and fields on instances of the given typeT
. When feasible, useBinder.getMembersInjector(TypeLiteral)
instead to get increased up front error detection.- Specified by:
getMembersInjector
in interfaceInjector
- Parameters:
type
- type to get members injector for- See Also:
for an alternative that offers up front error detection
-
getProvider
public <T> Provider<T> getProvider(java.lang.Class<T> type)
Description copied from interface:Injector
Returns the provider used to obtain instances for the given type. When feasible, avoid using this method, in favor of having Guice inject your dependencies ahead of time.- Specified by:
getProvider
in interfaceInjector
- See Also:
for an alternative that offers up front error detection
-
getProviderOrThrow
<T> Provider<T> getProviderOrThrow(Dependency<T> dependency, Errors errors) throws ErrorsException
- Throws:
ErrorsException
-
getProvider
public <T> Provider<T> getProvider(Key<T> key)
Description copied from interface:Injector
Returns the provider used to obtain instances for the given injection key. When feasible, avoid using this method, in favor of having Guice inject your dependencies ahead of time.- Specified by:
getProvider
in interfaceInjector
- Specified by:
getProvider
in interfaceLookups
- See Also:
for an alternative that offers up front error detection
-
getInstance
public <T> T getInstance(Key<T> key)
Description copied from interface:Injector
Returns the appropriate instance for the given injection key; equivalent togetProvider(key).get()
. When feasible, avoid using this method, in favor of having Guice inject your dependencies ahead of time.- Specified by:
getInstance
in interfaceInjector
-
getInstance
public <T> T getInstance(java.lang.Class<T> type)
Description copied from interface:Injector
Returns the appropriate instance for the given injection type; equivalent togetProvider(type).get()
. When feasible, avoid using this method, in favor of having Guice inject your dependencies ahead of time.- Specified by:
getInstance
in interfaceInjector
-
getLocalContext
InternalContext getLocalContext()
Only to be called by theSingletonScope
provider.
-
enterContext
InternalContext enterContext()
Looks up thread local context andenters
it or creates a new context if necessary.All callers of this are responsible for calling
InternalContext.close()
. Typical usage should look like:InternalContext ctx = injector.enterContext(); try { ... use ctx ... } finally { ctx.close(); }
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-