BindingKey

play.api.inject.BindingKey
See theBindingKey companion object
final case class BindingKey[T](clazz: Class[T], qualifier: Option[QualifierAnnotation])

A binding key.

A binding key consists of a class and zero or more JSR-330 qualifiers.

Value parameters

clazz

The class to bind.

qualifier

An optional qualifier.

Attributes

See also

The Module class for information on how to provide bindings.

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Constructors

def this(clazz: Class[T])

Concrete methods

def asJava: BindingKey[T]
def qualifiedWith[A <: Annotation](instance: A): BindingKey[T]

Qualify this binding key with the given instance of an annotation.

Qualify this binding key with the given instance of an annotation.

This can be used to specify bindings with annotations that have particular values.

Attributes

def qualifiedWith[A <: Annotation](annotation: Class[A]): BindingKey[T]

Qualify this binding key with the given 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:

 import scala.annotation._

 @target.param
 class Cached extends StaticAnnotation

 ...

 bind[Foo].qualifiedWith(classOf[Cached]).to[FooCached],
 bind[Foo].to[FooImpl]

 ...

 class MyController @Inject() (@Cached foo: Foo) {
   ...
 }

In the above example, the controller will get the cached Foo service.

Attributes

def qualifiedWith[A <: Annotation : ClassTag]: BindingKey[T]

Qualify this binding key with the given 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:

 import scala.annotation._

 @target.param
 class Cached extends StaticAnnotation

 ...

 bind[Foo].qualifiedWith[Cached].to[FooCached],
 bind[Foo].to[FooImpl]

 ...

 class MyController @Inject() (@Cached foo: Foo) {
   ...
 }

In the above example, the controller will get the cached Foo service.

Attributes

Qualify this binding key with the given 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:

 bind[Foo].qualifiedWith("cached").to[FooCached],
 bind[Foo].to[FooImpl]

 ...

 class MyController @Inject() (@Named("cached") foo: Foo) {
   ...
 }

In the above example, the controller will get the cached Foo service.

Attributes

def to(implementation: Class[_ <: T]): Binding[T]

Bind this binding key to the given implementation class.

Bind this binding key to the given implementation class.

This class will be instantiated and injected by the injection framework.

Attributes

def to[C <: T : ClassTag]: Binding[T]

Bind this binding key to the given implementation class.

Bind this binding key to the given implementation class.

This class will be instantiated and injected by the injection framework.

Attributes

def to(provider: Provider[_ <: T]): Binding[T]

Bind this binding key to the given provider instance.

Bind this binding key to the given provider instance.

This provider instance will be invoked to obtain the implementation for the key.

Attributes

def to[A <: T](instance: => A): Binding[T]

Bind this binding key to the given instance.

Bind this binding key to the given instance.

Attributes

def to(key: BindingKey[_ <: T]): Binding[T]

Bind this binding key to another binding key.

Bind this binding key to another binding key.

Attributes

def toInstance(instance: T): Binding[T]

Bind this binding key to the given instance.

Bind this binding key to the given instance.

Attributes

def toProvider[P <: Provider[_ <: T]](provider: Class[P]): Binding[T]

Bind this binding key to the given provider class.

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.

Attributes

def toProvider[P <: Provider[_ <: T] : ClassTag]: Binding[T]

Bind this binding key to the given provider class.

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.

Attributes

def toSelf: Binding[T]

Bind this binding key to itself.

Bind this binding key to itself.

Attributes

override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Any

Inherited methods

Attributes

Inherited from:
Product

Attributes

Inherited from:
Product