public class SpincastRequestScope extends Object implements com.google.inject.Scope
request.
Modified from: https://github.com/google/guice/wiki/CustomScopes:
Scopes a single execution of a block of code. Apply this scope with a try/finally block:
scope.enter();
try {
// explicitly seed some seed objects...
scope.seed(Key.get(SomeObject.class), someObject);
// create and access scoped objects
} finally {
scope.exit();
}
The scope can be initialized with one or more seed values by calling
seed(key, value) before the injector will be called upon to
provide for this key. A typical use is for a servlet filter to enter/exit the
scope, representing a Request Scope, and seed HttpServletRequest and
HttpServletResponse. For each key inserted with seed(), you must include a
corresponding binding:
bind(key)
.toProvider(SimpleScope.<KeyClass>seededKeyProvider())
.in(ScopeAnnotation.class);
| Modifier and Type | Field and Description |
|---|---|
protected org.slf4j.Logger |
logger |
| Constructor and Description |
|---|
SpincastRequestScope() |
| Modifier and Type | Method and Description |
|---|---|
void |
enter() |
void |
exit() |
protected <T> Map<com.google.inject.Key<?>,Object> |
getScopedObjectMap(com.google.inject.Key<T> key) |
static <T> com.google.inject.Provider<T> |
getSeedErrorProvider(com.google.inject.Key key)
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> unscoped) |
<T> void |
seed(Class<T> clazz,
T value) |
<T> void |
seed(com.google.inject.Key<T> key,
T value) |
public void enter()
public void exit()
public <T> void seed(com.google.inject.Key<T> key,
T value)
public <T> void seed(Class<T> clazz, T value)
public <T> com.google.inject.Provider<T> scope(com.google.inject.Key<T> key,
com.google.inject.Provider<T> unscoped)
scope in interface com.google.inject.Scopeprotected <T> Map<com.google.inject.Key<?>,Object> getScopedObjectMap(com.google.inject.Key<T> key)
public static <T> com.google.inject.Provider<T> getSeedErrorProvider(com.google.inject.Key key)
Copyright © 2018. All rights reserved.