I was writing a kotlin Guice module class that exp...
# announcements
c
I was writing a kotlin Guice module class that exposed the binding builder as a DSL:
Copy code
abstract class KotlinModule() : AbstractModule() {
    protected inline fun <reified T : Any> bind():
        AnnotatedBindingBuilder<T> = bind(T::class.java)

    protected inline fun <reified T : Any> bindSet(closure: Multibinder<T>.() -> Unit) {
        Multibinder.newSetBinder(binder(), T::class.java).closure()
    }

    protected inline fun <reified K : Any, reified V : Any> bindMap(closure: MapBinder<K, V>.() -> Unit) {
        MapBinder.newMapBinder(binder(), K::class.java, V::class.java).closure()
    }

    fun <T : Any> Multibinder<T>.bind() = addBinding()
    fun <K : Any, V : Any> MapBinder<K, V>.bind(key: K) = addBinding(key)

    inline fun <reified T : Any> LinkedBindingBuilder<in T>.to(): ScopedBindingBuilder? = to(T::class.java)
}