public final class BindingKey<T>
extends java.lang.Object
A binding key consists of a class and zero or more JSR-330 qualifiers.
See the Module
class for information on how to provide bindings.
Constructor and Description |
---|
BindingKey(play.api.inject.BindingKey<T> underlying) |
BindingKey(java.lang.Class<T> clazz) |
BindingKey(java.lang.Class<T> clazz,
java.util.Optional<QualifierAnnotation> qualifier)
A binding key.
|
Modifier and Type | Method and Description |
---|---|
play.api.inject.BindingKey<T> |
asScala() |
java.lang.Class<T> |
getClazz() |
java.util.Optional<QualifierAnnotation> |
getQualifier() |
<A extends java.lang.annotation.Annotation> |
qualifiedWith(A instance)
Qualify this binding key with the given instance of an annotation.
|
<A extends java.lang.annotation.Annotation> |
qualifiedWith(java.lang.Class<A> annotation)
Qualify this binding key with the given annotation.
|
BindingKey<T> |
qualifiedWith(java.lang.String name)
Qualify this binding key with the given name.
|
Binding<T> |
to(BindingKey<? extends T> key)
Bind this binding key to another binding key.
|
Binding<T> |
to(java.lang.Class<? extends T> implementation)
Bind this binding key to the given implementation class.
|
Binding<T> |
to(javax.inject.Provider<? extends T> provider)
Bind this binding key to the given provider instance.
|
<A extends T> |
to(java.util.function.Supplier<A> instance)
Bind this binding key to the given instance.
|
Binding<T> |
toInstance(T instance)
Bind this binding key to the given instance.
|
<P extends javax.inject.Provider<? extends T>> |
toProvider(java.lang.Class<P> provider)
Bind this binding key to the given provider class.
|
Binding<T> |
toSelf()
Bind this binding key to itself.
|
java.lang.String |
toString() |
public BindingKey(java.lang.Class<T> clazz, java.util.Optional<QualifierAnnotation> qualifier)
A binding key consists of a class and zero or more JSR-330 qualifiers.
See the Module
class for information on how to provide bindings.
clazz
- The class to bind.qualifier
- An optional qualifier.public BindingKey(play.api.inject.BindingKey<T> underlying)
public BindingKey(java.lang.Class<T> clazz)
public java.lang.Class<T> getClazz()
public java.util.Optional<QualifierAnnotation> getQualifier()
public <A extends java.lang.annotation.Annotation> BindingKey<T> qualifiedWith(A instance)
This can be used to specify bindings with annotations that have particular values.
public <A extends java.lang.annotation.Annotation> BindingKey<T> qualifiedWith(java.lang.Class<A> annotation)
For example, you may have both a cached implementation, and a direct implementation of a service. To differentiate between them, you may define a Cached annotation:
bindClass(Foo.class).qualifiedWith(Cached.class).to(FooCached.class),
bindClass(Foo.class).to(FooImpl.class)
...
class MyController {
{@literal @}Inject
MyController({@literal @}Cached Foo foo) {
...
}
...
}
In the above example, the controller will get the cached Foo
service.public BindingKey<T> qualifiedWith(java.lang.String name)
For example, you may have both a cached implementation, and a direct implementation of a service. To differentiate between them, you may decide to name the cached one:
bindClass(Foo.class).qualifiedWith("cached").to(FooCached.class),
bindClass(Foo.class).to(FooImpl.class)
...
class MyController {
{@literal @}Inject
MyController({@literal @}Named("cached") Foo foo) {
...
}
...
}
In the above example, the controller will get the cached `Foo` service.public Binding<T> to(java.lang.Class<? extends T> implementation)
This class will be instantiated and injected by the injection framework.
public Binding<T> to(javax.inject.Provider<? extends T> provider)
This provider instance will be invoked to obtain the implementation for the key.
public <A extends T> Binding<T> to(java.util.function.Supplier<A> instance)
public Binding<T> to(BindingKey<? extends T> key)
public <P extends javax.inject.Provider<? extends T>> Binding<T> toProvider(java.lang.Class<P> provider)
The dependency injection framework will instantiate and inject this provider, and then invoke its `get` method whenever an instance of the class is needed.
public java.lang.String toString()
toString
in class java.lang.Object
public play.api.inject.BindingKey<T> asScala()