A - The type of IAdaptable this Scope is bound to.public class AdaptableScope<A extends IAdaptable>
extends java.lang.Object
implements com.google.inject.Scope
Scope that is bound to an IAdaptable-compliant type
and has to be scoped to a respective instance of that type.
After the scope has been entered for an IAdaptable instance (which
automatically switches the scope to this IAdaptable instance), the
AdaptableScope will maintain a set of scoped objects for the
respective IAdaptable instance. The scoped provider being returned by
scope(Key, Provider) will always (recycle) objects from this set of
scoped objects, only creating new instances if a respective instance is not
already contained in the set of scoped objects.
The AdaptableScope may be switched between all IAdaptable
instances, for which it has been entered before (upon entering, it will
automatically switch to the instance it has been entered for). The scoped
provider will always refer to the set of scoped objects bound to the
IAdaptable instance the scope was switched to last, preserving the
set of objects instances for all other IAdaptable instances.
Leaving the scope for an IAdaptable instance will clear the set of
scoped objects for this IAdaptable instance, so no scoped objects may
be recycled afterwards. The AdaptableScope will have to be re-entered
for the IAdaptable instance after it has been left for it.
| Constructor and Description |
|---|
AdaptableScope(java.lang.Class<? extends A> type)
Creates a new
AdaptableScope for the given IAdaptable
type. |
| Modifier and Type | Method and Description |
|---|---|
void |
enter(A instance)
Enters this scope for the given
IAdaptable instance and binds the
scope to it, so that the Provider returned by
scope(Key, Provider) will return (recycled) instances from a set
of scoped objects maintained for the IAdaptable instance, until
the scope is entered and/or bound to another IAdaptable instance
(see switchTo(IAdaptable)) or left (see
leave(IAdaptable)) for it. |
void |
leave(A instance)
Leaves this scope for the given
IAdaptable instance, resulting in
unbinding this scope from it and clearing the set of scoped objects
maintained for it. |
<T> com.google.inject.Provider<T> |
scope(com.google.inject.Key<T> key,
com.google.inject.Provider<T> unscoped) |
void |
switchTo(A instance)
Switches this scope to be bound to the given
IAdaptable instance,
so that the Provider returned by scope(Key, Provider)
will afterwards return (recycled) instances from the set of scoped
objects that is maintained for the respective IAdaptable
instance, until the scope is bound to another IAdaptable instance
(switchTo(IAdaptable)) or left ( leave(IAdaptable)) for
the given instance. |
public AdaptableScope(java.lang.Class<? extends A> type)
AdaptableScope for the given IAdaptable
type.type - The IAdaptable type this scope is responsible for.public void enter(A instance)
IAdaptable instance and binds the
scope to it, so that the Provider returned by
scope(Key, Provider) will return (recycled) instances from a set
of scoped objects maintained for the IAdaptable instance, until
the scope is entered and/or bound to another IAdaptable instance
(see switchTo(IAdaptable)) or left (see
leave(IAdaptable)) for it.instance - The IAdaptable instance to enter (and bind) this
AdaptableScope for.public void leave(A instance)
IAdaptable instance, resulting in
unbinding this scope from it and clearing the set of scoped objects
maintained for it.
The scope may not be switched back to the IAdaptable instance
before having been re-entered for it (see enter(IAdaptable)).
instance - The IAdaptable instance to (unbind and) leave this
AdaptableScope for.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.Scopepublic void switchTo(A instance)
IAdaptable instance,
so that the Provider returned by scope(Key, Provider)
will afterwards return (recycled) instances from the set of scoped
objects that is maintained for the respective IAdaptable
instance, until the scope is bound to another IAdaptable instance
(switchTo(IAdaptable)) or left ( leave(IAdaptable)) for
the given instance.
When switching the scope to another IAdaptable instance, the set
of objects maintained for previously bound IAdaptable instances
is preserved (unless the scope is left for them) and will be re-used
after switching back to the respective IAdaptable instance.
Before switching the scope to an IAdaptable instance, the scope
has to be initially entered (enter(IAdaptable)) for it, which
will automatically bind the scope to it.
instance - The IAdaptable instance to bind this
AdaptableScope to.Copyright (c) 2014 itemis AG and others. All rights reserved.