Skip to content

Commit 5c9cce8

Browse files
committed
Add multibindings module
1 parent d5254a7 commit 5c9cce8

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

kotlin-guiced.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ apply {
2121
val PUBLISHED_CONFIGURATION_NAME = "published"
2222

2323
allprojects {
24-
version = "0.0.2"
24+
version = "0.0.3-SNAPSHOT"
2525
group = "org.jlleitschuh.guice"
2626
}
2727

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dependencies {
2+
compile(project(":kotlin-guiced-core"))
3+
compile(group = "com.google.inject.extensions", name = "guice-multibindings", version = "4.1.0")
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.jlleitschuh.guice.multibindings
2+
3+
import com.google.inject.Binder
4+
import com.google.inject.multibindings.Multibinder
5+
import org.jlleitschuh.guice.key
6+
import org.jlleitschuh.guice.typeLiteral
7+
import kotlin.reflect.KClass
8+
9+
object KotlinMultibinder {
10+
inline fun <reified T> newSetBinder(binder: Binder) = Multibinder.newSetBinder(binder, key<T>())!!
11+
12+
inline fun <reified T> newSetBinder(binder: Binder, annotationType: KClass<out Annotation>) =
13+
Multibinder.newSetBinder(binder, typeLiteral<T>(), annotationType.java)!!
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.jlleitschuh.guice.multibindings
2+
3+
import com.google.inject.AbstractModule
4+
import io.kotlintest.specs.StringSpec
5+
6+
class MultibinderTest : StringSpec() {
7+
@Target(AnnotationTarget.CLASS)
8+
@Retention(AnnotationRetention.RUNTIME)
9+
annotation class TestAnnotation
10+
interface TestInterface
11+
init {
12+
"should be able to bind an interface" {
13+
object : AbstractModule() {
14+
override fun configure() {
15+
KotlinMultibinder.newSetBinder<TestInterface>(binder())
16+
}
17+
}
18+
}
19+
"should be able to bind an interface and an annotation" {
20+
object : AbstractModule() {
21+
override fun configure() {
22+
KotlinMultibinder.newSetBinder<TestInterface>(binder(), TestAnnotation::class)
23+
}
24+
}
25+
}
26+
}
27+
}

settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
include ":core"
2+
include ":multibindings"
23

34
rootProject.name = 'kotlin-guiced'
45
rootProject.buildFileName = "build.gradle.kts"

0 commit comments

Comments
 (0)