T
- The source typepublic interface Binding<T>
Injector
.
It represents a binding action from one type to another type.Modifier and Type | Method and Description |
---|---|
Binding<T> |
exclude(Class<?> exclude)
Exclude the provided type from being matched when examining injection
points.
|
Binding<T> |
fixed()
Configure the binding so that its results are 'fixed'.
|
Binding<T> |
shared()
Configure the binding so that a shared instance is always used when
satisfying matched injection points, effectively making it a singleton or
memoized within its container.
|
void |
to(Class<? extends T> impl)
Bind to an implementation type non-terminally.
|
void |
to(Class<? extends T> impl,
boolean chained)
Complete this binding by specifying a subtype that will satisfy the
desired type.
|
void |
to(T instance)
Complete this binding by specifying an instance to use.
|
void |
toNull()
Complete this binding by explicitly binding to
null . |
void |
toNull(Class<? extends T> type)
Complete this binding by explicitly binding to
null with a type. |
void |
toProvider(Class<? extends javax.inject.Provider<? extends T>> provider)
Complete this binding by specifying a Provider class to be instantiated
and used to create instances of type T.
|
void |
toProvider(javax.inject.Provider<? extends T> provider)
Complete this binding by specifying a Provider instance that will be used
to create instances of type T to satisfy this binding.
|
void |
toSatisfaction(Satisfaction sat)
Bind this binding directly to a satisfaction.
|
Binding<T> |
unqualified()
Configure the binding to only match injection points that have no
qualifier.
|
Binding<T> |
unshared()
Configure the binding so that new instances are always created when
satisfying matched injection.
|
Binding<T> |
withAnyQualifier()
Configure the binding to match injection points that have any qualifier annotation (including
no qualifier).
|
Binding<T> |
withQualifier(Annotation annot)
Configure the binding to match injection points that have been annotated with the exact
annotation instance.
|
Binding<T> |
withQualifier(Class<? extends Annotation> qualifier)
Configure the binding to match the given
Qualifier annotation. |
Binding<T> withQualifier(@Nonnull Class<? extends Annotation> qualifier)
Configure the binding to match the given Qualifier
annotation.
The given annotation type must be annotated with Qualifier
. The
created binding will match injection points only if the qualifier is
applied to the injection point, unless the annotation inherits from the
default qualifier.
This will override any previous name or qualifier annotation.
qualifier
- The Qualifier that must matchBinding<T> withQualifier(@Nonnull Annotation annot)
This will override any previous name or qualifier annotation.
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.
annot
- The annotation instance to match.Binding<T> withAnyQualifier()
This will override any previous name or qualifier annotation.
Binding<T> unqualified()
Configure the binding to only match injection points that have no qualifier. By default, the binding matches any injection point with the given type, whether or not its been qualified. A qualified binding to the same type will still be preferred first when resolving a qualified injection point.
Binding<T> exclude(@Nonnull Class<?> exclude)
BindRules
for
super and sub types. Excluded classes for a binding will not have
BindRules generated for them.exclude
- The type to exclude from automated rule generationBinding<T> shared()
Binding<T> unshared()
Binding<T> fixed()
void to(@Nonnull Class<? extends T> impl, boolean chained)
Complete this binding by specifying a subtype that will satisfy the desired type. The implementation does not have to be instantiable; if it's not then additional bindings must be configured to bind to reach an instantiable type. It is recommended for types to be instantiable.
The given type may have its own dependencies that will have to be satisfied by other bindings.
It is permissible to have two bindings forming a chain, like
A → B → C
. The chained
parameter controls
whether the chain is followed. If chained == false
for the A → B
binding, then the B → C
binding is not followed (and the A → B
binding is called terminal).
impl
- The implementation typechained
- Whether further binding lookup will be done on the implementation type.
true
allows lookup, false
creates a terminal binding.void to(@Nonnull Class<? extends T> impl)
to(Class, boolean)
as this.to(impl, true)
.impl
- The implementation type.void to(@Nullable T instance)
shared()
or
unshared()
is effectively ignored.instance
- The instance to use. If null
, binds explicitly to
null.void toProvider(@Nonnull Class<? extends javax.inject.Provider<? extends T>> provider)
provider
- The provider type that will satisfy this bindingvoid toProvider(@Nonnull javax.inject.Provider<? extends T> provider)
provider
- The provider instancevoid toNull()
null
. The resulting
bindings may not create an instantiable graph, as non-nullable injection points
still require a non-null instance.void toNull(Class<? extends T> type)
null
with a type.type
- The type of null
to bind.toNull()
void toSatisfaction(@Nonnull Satisfaction sat)
Note: this method is intended for use by applications that extend Grapht, or for bindings to other JVM languages. Most applications will have no use for this method, and developers consider if one of the other methods is more applicable for their situation.
Bindings to satisfactions are always terminal.
sat
- The satisfaction to bind to.Copyright © 2016 GroupLens Research. All rights reserved.