public.javadoc.org.spincast.core.guice.SpincastRequestScope.html Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spincast-website Show documentation
Show all versions of spincast-website Show documentation
Source code for the https://www.spincast.org website.
SpincastRequestScope (org.spincast:spincast-framework 1.0.0 API)
org.spincast.core.guice
Class SpincastRequestScope
- java.lang.Object
-
- org.spincast.core.guice.SpincastRequestScope
-
- All Implemented Interfaces:
- com.google.inject.Scope
public class SpincastRequestScope
extends Object
implements com.google.inject.Scope
Guice scope for a 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);
- Author:
- Jesse Wilson, Fedor Karpelevitch
-
-
Field Summary
Fields
Modifier and Type
Field and Description
protected org.slf4j.Logger
logger
-
Constructor Summary
Constructors
Constructor and Description
SpincastRequestScope()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods
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)
-
-
Method Detail
-
enter
public void enter()
-
exit
public void exit()
-
seed
public <T> void seed(com.google.inject.Key<T> key,
T value)
-
seed
public <T> void seed(Class<T> clazz,
T value)
-
scope
public <T> com.google.inject.Provider<T> scope(com.google.inject.Key<T> key,
com.google.inject.Provider<T> unscoped)
- Specified by:
scope
in interface com.google.inject.Scope
-
getScopedObjectMap
protected <T> Map<com.google.inject.Key<?>,Object> getScopedObjectMap(com.google.inject.Key<T> key)
-
getSeedErrorProvider
public 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.
- Returns:
- typed provider
Copyright © 2019. All rights reserved.