toothpick icon indicating copy to clipboard operation
toothpick copied to clipboard

Add some KTP extensions

Open osipxd opened this issue 5 years ago • 1 comments

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)
}

osipxd avatar May 07 '20 08:05 osipxd

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 :)

dlemures avatar Jun 12 '20 22:06 dlemures