Package pl.morgwai.base.guice.scopes
Class InjectionContext
- java.lang.Object
-
- pl.morgwai.base.guice.scopes.InjectionContext
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
TrackableContext
public abstract class InjectionContext extends Object implements Serializable
Stores objects scoped to the context of some processing/call/request/session, such as an RPC, a servlet request processing, a session combining several calls etc. Stored objects can be obtained via Guice injections configured with bindings scoped in the associatedContextScope
.Note: most context classes should rather extend
TrackableContext
subclass instead of this one. The main exception are context types that are induced by other contexts: seeInducedContextScope
.Subclasses usually add properties and methods specific to their type, like their call's arguments, a reference to their session object etc.
Multiple threads may run within the same context, but the scoped objects that they access must be thread-safe or properly synchronized.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description InjectionContext()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <T> T
provideIfAbsent(Key<T> key, Provider<T> provider)
Obtains the object given bykey
.void
removeScopedObject(Key<?> key)
Removes the object given bykey
from this context.
-
-
-
Method Detail
-
removeScopedObject
public void removeScopedObject(Key<?> key)
Removes the object given bykey
from this context. This is sometimes useful to force the associatedContextScope
to obtain a new instance from the unscoped provider if the current one is not usable anymore (for example a timed-out connection, etc).Note: If multiple threads run within the same context, care must be taken to prevent some of them from retaining the old stale instances.
-
-