Class BindingKey<T>
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 Summary
ConstructorsConstructorDescriptionBindingKey(Class<T> clazz) BindingKey(Class<T> clazz, Optional<QualifierAnnotation> qualifier) A binding key.BindingKey(play.api.inject.BindingKey<T> underlying) -
Method Summary
Modifier and TypeMethodDescriptionplay.api.inject.BindingKey<T>asScala()getClazz()<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.qualifiedWith(String name) Qualify this binding key with the given name.Bind this binding key to the given provider instance.Bind this binding key to the given implementation class.Bind this binding key to the given instance.to(BindingKey<? extends T> key) Bind this binding key to another binding key.toInstance(T instance) Bind this binding key to the given instance.toProvider(Class<P> provider) Bind this binding key to the given provider class.toSelf()Bind this binding key to itself.toString()
-
Constructor Details
-
BindingKey
A binding key.A binding key consists of a class and zero or more JSR-330 qualifiers.
See the
Moduleclass for information on how to provide bindings.- Parameters:
clazz- The class to bind.qualifier- An optional qualifier.
-
BindingKey
-
BindingKey
-
-
Method Details
-
getClazz
-
getQualifier
-
qualifiedWith
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
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) { ... } ... }Fooservice. -
qualifiedWith
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
Bind this binding key to the given implementation class.This class will be instantiated and injected by the injection framework.
-
to
Bind this binding key to the given provider instance.This provider instance will be invoked to obtain the implementation for the key.
-
to
Bind this binding key to the given instance. -
to
Bind this binding key to another binding key. -
toProvider
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.
-
toInstance
Bind this binding key to the given instance. -
toSelf
Bind this binding key to itself. -
toString
-
asScala
-