public interface Context
Context is the main entry point for configuring bind rules using the fluent
API. The dependency injector uses the contexts to limit the scope of a
binding. Every time a dependency is satisfied, that type (and possibly Qualifier
)
is pushed onto the context stack. Thus, if two different types each require a
Foo, there can be two different bindings activated depending on which first
type is in the context stack.
The "root" context is an empty stack, and will always be matched. When
creating bindings, the context stack can be configured by calling
in(Class)
or in(Class, Class)
.
Modifier and Type | Method and Description |
---|---|
Context |
at(Annotation qualifier,
Class<?> type)
Create a new Context that extends the current context stack with the given class, qualified
by the specific Annotation instance.
|
Context |
at(Class<?> type)
Create a new Context that extends the current context stack with the given class type as an
anchored match.
|
Context |
at(Class<? extends Annotation> qualifier,
Class<?> type)
Create a new Context that extends the current context stack with the given class and
Qualifier annotation as an anchored match. |
<T> Binding<T> |
bind(Class<? extends Annotation> qual,
Class<T> type)
Start a new binding for a qualified type.
|
<T> Binding<T> |
bind(Class<T> type)
Start a new binding for the given type T within the scope of this
context.
|
<T> Binding<T> |
bindAny(Class<T> type)
Start a new binding for a type irrespective of qualifier.
|
Context |
in(Annotation qualifier,
Class<?> type)
Deprecated.
|
Context |
in(Class<?> type)
Deprecated.
Use
within(Class) . |
Context |
in(Class<? extends Annotation> qualifier,
Class<?> type)
Deprecated.
Use
within(Class, Class) . |
Context |
matching(ContextPattern pattern)
Restruct context to matching a particular pattern.
|
Context |
within(Annotation qualifier,
Class<?> type)
Create a new Context that extends the current context stack with the
given class, qualified by the specific Annotation instance.
|
Context |
within(Class<?> type)
Create a new Context that extends the current context stack with the
given class type.
|
Context |
within(Class<? extends Annotation> qualifier,
Class<?> type)
Create a new Context that extends the current context stack with the
given class and
Qualifier annotation. |
<T> Binding<T> bind(Class<T> type)
AllowUnqualifiedMatch
.T
- The matched source typetype
- The raw class that is matched<T> Binding<T> bind(Class<? extends Annotation> qual, Class<T> type)
bind(type).withQualifier(qual)
.T
- The type to bind.qual
- The type's qualifier.type
- The type to bind.Binding.withQualifier(Class)
<T> Binding<T> bindAny(Class<T> type)
bind(type).withAnyQualifier()
.type
- The type.@Deprecated Context in(Class<?> type)
within(Class)
.@Deprecated Context in(@Nullable Class<? extends Annotation> qualifier, Class<?> type)
within(Class, Class)
.@Deprecated Context in(@Nullable Annotation qualifier, Class<?> type)
within(Annotation, Class)
.Context within(Class<?> type)
Qualifier
. This is equivalent
to within(null, type);
type
- The type to extend this context byContext within(@Nullable Class<? extends Annotation> qualifier, Class<?> type)
Qualifier
annotation. If the qualifier is null,
the default or null qualifier is used.qualifier
- The qualifier type that must be matched along with the typetype
- The type to extend this context byContext within(@Nullable Annotation qualifier, Class<?> type)
The annotation provided must be serializable. Annotations built by AnnotationBuilder
(recommended) or retrieved from the Java
reflection API are serializable; if you use some other annotation implementation, it must be
serializable.
qualifier
- The qualifier instance that must be matched along with
the typetype
- The type to extend this context byContext matching(ContextPattern pattern)
pattern
- The context pattern to match.Context at(Class<?> type)
Qualifier
. This is equivalent to
at(null, type);
type
- The type to extend this context byat(Class, Class)
Context at(@Nullable Class<? extends Annotation> qualifier, Class<?> type)
Qualifier
annotation as an anchored match. If the qualifier is null, the default or null
qualifier is used.
Unlike in(Class,Class)
, this match is anchored — that is, it only
matches at the end of a context chain. Context is matched if it ends with this or,
if further context is opened inside this context, if the inner context matches immediately.
qualifier
- The qualifier type that must be matched along with the typetype
- The type to extend this context byContext at(@Nullable Annotation qualifier, Class<?> type)
The annotation provided must be serializable. Annotations built by AnnotationBuilder
(recommended) or retrieved from the Java
reflection API are serializable; if you use some other annotation implementation, it must be
serializable.
qualifier
- The qualifier instance that must be matched along with the typetype
- The type to extend this context byCopyright © 2014 GroupLens Research. All Rights Reserved.