Package com.google.inject
Class Scopes
java.lang.Object
com.google.inject.Scopes
Built-in scope implementations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final BindingScopingVisitor<Boolean>
static final Scope
No scope; the same as not applying any scope at all.static final Scope
One instance perInjector
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
isCircularProxy
(Object object) Returns true if the object is a proxy for a circular dependency, constructed by Guice because it encountered a circular dependency.static boolean
isScoped
(Binding<?> binding, Scope scope, Class<? extends Annotation> scopeAnnotation) Returns true ifbinding
has the given scope.static boolean
isSingleton
(Binding<?> binding) Returns true ifbinding
is singleton-scoped.
-
Field Details
-
SINGLETON
-
NO_SCOPE
No scope; the same as not applying any scope at all. Each time the Injector obtains an instance of an object with "no scope", it injects this instance then immediately forgets it. When the next request for the same binding arrives it will need to obtain the instance over again.This exists only in case a class has been annotated with a scope annotation such as
@Singleton
, and you need to override this to "no scope" in your binding.- Since:
- 2.0
-
IS_SINGLETON_VISITOR
-
-
Constructor Details
-
Scopes
private Scopes()
-
-
Method Details
-
isSingleton
Returns true ifbinding
is singleton-scoped. If the binding is alinked key binding
and belongs to an injector (ie. it was retrieved viaInjector.getBinding()
), then this method will also true if the target binding is singleton-scoped.- Since:
- 3.0
-
isScoped
public static boolean isScoped(Binding<?> binding, Scope scope, Class<? extends Annotation> scopeAnnotation) Returns true ifbinding
has the given scope. If the binding is alinked key binding
and belongs to an injector (ie. it was retrieved viaInjector.getBinding()
), then this method will also true if the target binding has the given scope.- Parameters:
binding
- binding to checkscope
- scope implementation instancescopeAnnotation
- scope annotation class- Since:
- 4.0
-
isCircularProxy
Returns true if the object is a proxy for a circular dependency, constructed by Guice because it encountered a circular dependency. Scope implementations should be careful to not cache circular proxies, because the proxies are not intended for general purpose use. (They are designed just to fulfill the immediate injection, not all injections. Caching them can lead to IllegalArgumentExceptions or ClassCastExceptions.)- Since:
- 4.0
-