-
Notifications
You must be signed in to change notification settings - Fork 6
/
LinkedBindingBuilderScope.kt
40 lines (34 loc) · 1.44 KB
/
LinkedBindingBuilderScope.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package org.jlleitschuh.guice.binder
import com.google.inject.Key
import com.google.inject.TypeLiteral
import com.google.inject.binder.LinkedBindingBuilder
import kotlin.reflect.KClass
open class LinkedBindingBuilderScope<T : Any>(
private val linkedBindingBuilder: LinkedBindingBuilder<T>) :
LinkedBindingBuilder<T> by linkedBindingBuilder {
/*
* I've thought about providing `to` as an infix operation, but realized it's a terrible idea.
* The possible confusion of meaning between this `to` and the the one that creates a `Pair` is way too easy
* a mistake to make.
*/
/**
* See the EDSL examples at [com.google.inject.Binder].
*/
fun to(implementation: KClass<out T>): ScopedBindingBuilderScope =
to(implementation.java)
/**
* See the EDSL examples at [com.google.inject.Binder].
*/
override fun to(implementation: Class<out T>): ScopedBindingBuilderScope =
ScopedBindingBuilderScope(linkedBindingBuilder.to(implementation))
/**
* See the EDSL examples at [com.google.inject.Binder].
*/
override fun to(implementation: TypeLiteral<out T>): ScopedBindingBuilderScope =
ScopedBindingBuilderScope(linkedBindingBuilder.to(implementation))
/**
* See the EDSL examples at [com.google.inject.Binder].
*/
override fun to(targetKey: Key<out T>): ScopedBindingBuilderScope =
ScopedBindingBuilderScope(linkedBindingBuilder.to(targetKey))
}