Package pl.morgwai.base.guice.scopes
Class ContextScope<ContextT extends TrackableContext<? super ContextT>>
- java.lang.Object
-
- pl.morgwai.base.guice.scopes.ContextScope<ContextT>
-
- All Implemented Interfaces:
Scope
- Direct Known Subclasses:
InducedContextScope
public class ContextScope<ContextT extends TrackableContext<? super ContextT>> extends Object implements Scope
Scopes objects to theContextT
instance that is current at a given moment (obtained from the associatedContextTracker
by default). AContextScope
instance is associated with one particular type of contexts: a subclass ofTrackableContext
, here denoted asContextT
. For example: aScope
ofContexts
ofHttpServletRequests
.Instances should usually be created at app startup to be used in bindings in user
Module
s.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
ContextScope.ScopedProvider<T>
Returned byscope(Key, Provider)
, provides objects scoped to aContext
that is current at the momentContextScope.ScopedProvider.get()
is called (as returned bygetContext()
).
-
Field Summary
Fields Modifier and Type Field Description protected ContextTracker<ContextT>
tracker
-
Constructor Summary
Constructors Constructor Description ContextScope(String name, ContextTracker<ContextT> tracker)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected InjectionContext
getContext()
Returns theContext
from which scoped objects should be obtained.String
getName()
<T> ContextScope.ScopedProvider<T>
scope(Key<T> key, Provider<T> producer)
Wrapsproducer
with aContextScope.ScopedProvider
.String
toString()
-
-
-
Field Detail
-
tracker
protected final ContextTracker<ContextT extends TrackableContext<? super ContextT>> tracker
-
-
Constructor Detail
-
ContextScope
public ContextScope(String name, ContextTracker<ContextT> tracker)
-
-
Method Detail
-
getName
public String getName()
-
scope
public <T> ContextScope.ScopedProvider<T> scope(Key<T> key, Provider<T> producer)
Wrapsproducer
with aContextScope.ScopedProvider
.
-
getContext
protected InjectionContext getContext()
Returns theContext
from which scoped objects should be obtained. Called during eachprovisioning
. By default returns the currentContext
obtained directly fromtracker
. May be overridden for example to return someContext
induced by the one from thetracker
.- See Also:
InducedContextScope
-
-