public final class GuiceSimpleScope extends Object implements com.google.inject.Scope
Important: Do not use outside of Soy code (treat as superpackage-private).
Apply this scope with a try/finally block:
scope.enter();
try (GuiceSimpleScope.InScope inScope = scope.enter()) {
// explicitly seed some seed objects
inScope.seed(SomeObject.class, someObject);
// create and access scoped objects
...
}
The scope can be initialized with one or more seed values by calling seed(key, value) or
seed(class, value) before the injector will be called upon to provide for this key.
For each key seeded with seed(), you must include a corresponding binding:
bind(key)
.toProvider(GuiceSimpleScope.<KeyClass>getUnscopedProvider())
.in(ScopeAnnotation.class);
| Modifier and Type | Class and Description |
|---|---|
class |
GuiceSimpleScope.InScope
An autoclosable object that can be used to seed and exit scopes.
|
| Constructor and Description |
|---|
GuiceSimpleScope() |
| Modifier and Type | Method and Description |
|---|---|
GuiceSimpleScope.InScope |
enter()
Enters an occurrence of this scope.
|
static <T> com.google.inject.Provider<T> |
getUnscopedProvider()
Returns a provider that always throws exception complaining that the object in question must be
seeded before it can be injected.
|
<T> com.google.inject.Provider<T> |
scope(com.google.inject.Key<T> key,
com.google.inject.Provider<T> unscopedProvider) |
public static <T> com.google.inject.Provider<T> getUnscopedProvider()
@CheckReturnValue public GuiceSimpleScope.InScope enter()
public <T> com.google.inject.Provider<T> scope(com.google.inject.Key<T> key,
com.google.inject.Provider<T> unscopedProvider)
scope in interface com.google.inject.Scope