toothpick
toothpick copied to clipboard
Add some KTP extensions
I've created some extensions for my project. Maybe it should be in KTP?
/** Shorter call of `bind(...).toInstance(...)`. Class of binding retrieved from [T]. */
inline fun <reified T : Any> Module.bindInstance(instance: T) {
bind(T::class).toInstance(instance)
}
/** Simplified syntax to install one module to scope. */
inline fun Scope.installModule(crossinline bindings: Module.() -> Unit): Scope {
return installModules(module { bindings() })
}
/** Close scope. */
fun Scope.close() {
KTP.closeScope(name)
}
Thank you for the idea!
Regarding the first one:
Module.bindInstance
we try to keep the following pattern so the api is predictable:
bind(x).to...
We will consider the other two for TP 4 as we plan to improve the API.
Thx again :)