Top Description Fields Constructors Methods
com.google.inject

public Class Scopes

extends Object
Class Inheritance
Imports
com.google.inject.internal.BindingImpl, .BytecodeGen, .SingletonScope, com.google.inject.spi.BindingScopingVisitor, .ExposedBinding, .LinkedKeyBinding, java.lang.annotation.Annotation

Built-in scope implementations.
Author
[email protected] (Bob Lee)

Field Summary

Modifier and TypeField and Description
private static final BindingScopingVisitor<Boolean>
public static final Scope
NO_SCOPE

No scope; the same as not applying any scope at all.

public static final Scope
SINGLETON

One instance per Injector.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static Injector
getInjector(LinkedKeyBinding<?> linkedKeyBinding)

public static 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.

public static boolean
isScoped(Binding<?>
binding to check
binding
,
final Scope
scope implementation instance
scope
,
final Class<? extends Annotation>
scope annotation class
scopeAnnotation
)

Returns true if binding has the given scope.

public static boolean
isSingleton(Binding<?> binding)

Returns true if binding is singleton-scoped.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

IS_SINGLETON_VISITORback to summary
private static final BindingScopingVisitor<Boolean> IS_SINGLETON_VISITOR
NO_SCOPEback to summary
public static final Scope 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
SINGLETONback to summary
public static final Scope SINGLETON

One instance per Injector. Also see @Singleton.

Constructor Detail

Scopesback to summary
private Scopes()

Method Detail

getInjectorback to summary
private static Injector getInjector(LinkedKeyBinding<?> linkedKeyBinding)
isCircularProxyback to summary
public static 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. 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
isScopedback to summary
public static boolean isScoped(Binding<?> binding, final Scope scope, final Class<? extends Annotation> scopeAnnotation)

Returns true if binding has the given scope. If the binding is a linked key binding and belongs to an injector (ie. it was retrieved via Injector.getBinding()), then this method will also true if the target binding has the given scope.

Parameters
binding:Binding<?>

binding to check

scope:Scope

scope implementation instance

scopeAnnotation:Class<? extends Annotation>

scope annotation class

Since
4.0
isSingletonback to summary
public static boolean isSingleton(Binding<?> binding)

Returns true if binding is singleton-scoped. If the binding is a linked key binding and belongs to an injector (ie. it was retrieved via Injector.getBinding()), then this method will also true if the target binding is singleton-scoped.

Since
3.0