Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some KTP extensions #404

Open
osipxd opened this issue May 7, 2020 · 1 comment
Open

Add some KTP extensions #404

osipxd opened this issue May 7, 2020 · 1 comment
Milestone

Comments

@osipxd
Copy link
Contributor

osipxd commented May 7, 2020

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)
}
@dlemures dlemures added this to the 4.0.0 milestone Jun 12, 2020
@dlemures
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants