Class BindingKey<T>
- Object
-
- play.inject.BindingKey<T>
-
-
Constructor Summary
Constructors Constructor Description BindingKey(Class<T> clazz)
BindingKey(Class<T> clazz, Optional<QualifierAnnotation> qualifier)
A binding key.BindingKey(play.api.inject.BindingKey<T> underlying)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description play.api.inject.BindingKey<T>
asScala()
Class<T>
getClazz()
Optional<QualifierAnnotation>
getQualifier()
<A extends Annotation>
BindingKey<T>qualifiedWith(A instance)
Qualify this binding key with the given instance of an annotation.<A extends Annotation>
BindingKey<T>qualifiedWith(Class<A> annotation)
Qualify this binding key with the given annotation.BindingKey<T>
qualifiedWith(String name)
Qualify this binding key with the given name.Binding<T>
to(Class<? extends T> implementation)
Bind this binding key to the given implementation class.<A extends T>
Binding<T>to(Supplier<A> instance)
Bind this binding key to the given instance.Binding<T>
to(javax.inject.Provider<? extends T> provider)
Bind this binding key to the given provider instance.Binding<T>
to(BindingKey<? extends T> key)
Bind this binding key to another binding key.Binding<T>
toInstance(T instance)
Bind this binding key to the given instance.<P extends javax.inject.Provider<? extends T>>
Binding<T>toProvider(Class<P> provider)
Bind this binding key to the given provider class.Binding<T>
toSelf()
Bind this binding key to itself.String
toString()
-
-
-
Constructor Detail
-
BindingKey
public BindingKey(Class<T> clazz, Optional<QualifierAnnotation> qualifier)
A binding key.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.- Parameters:
clazz
- The class to bind.qualifier
- An optional qualifier.
-
BindingKey
public BindingKey(play.api.inject.BindingKey<T> underlying)
-
-
Method Detail
-
getQualifier
public Optional<QualifierAnnotation> getQualifier()
-
qualifiedWith
public <A extends Annotation> BindingKey<T> qualifiedWith(A instance)
Qualify this binding key with the given instance of an annotation.This can be used to specify bindings with annotations that have particular values.
-
qualifiedWith
public <A extends Annotation> BindingKey<T> qualifiedWith(Class<A> annotation)
Qualify this binding key with the given 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:
In the above example, the controller will get the cachedbindClass(Foo.class).qualifiedWith(Cached.class).to(FooCached.class), bindClass(Foo.class).to(FooImpl.class) ... class MyController { {@literal @}Inject MyController({@literal @}Cached Foo foo) { ... } ... }
Foo
service.
-
qualifiedWith
public BindingKey<T> qualifiedWith(String name)
Qualify this binding key with the given 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:
In the above example, the controller will get the cached `Foo` service.bindClass(Foo.class).qualifiedWith("cached").to(FooCached.class), bindClass(Foo.class).to(FooImpl.class) ... class MyController { {@literal @}Inject MyController({@literal @}Named("cached") Foo foo) { ... } ... }
-
to
public Binding<T> to(Class<? extends T> implementation)
Bind this binding key to the given implementation class.This class will be instantiated and injected by the injection framework.
-
to
public Binding<T> to(javax.inject.Provider<? extends T> provider)
Bind this binding key to the given provider instance.This provider instance will be invoked to obtain the implementation for the key.
-
to
public <A extends T> Binding<T> to(Supplier<A> instance)
Bind this binding key to the given instance.
-
to
public Binding<T> to(BindingKey<? extends T> key)
Bind this binding key to another binding key.
-
toProvider
public <P extends javax.inject.Provider<? extends T>> Binding<T> toProvider(Class<P> provider)
Bind this binding key to the given provider class.The dependency injection framework will instantiate and inject this provider, and then invoke its `get` method whenever an instance of the class is needed.
-
asScala
public play.api.inject.BindingKey<T> asScala()
-
-