-
Notifications
You must be signed in to change notification settings - Fork 114
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
Kotlin optimizations #305
Comments
There are some things that would be nice for kotlins.
fun Scope.inject(target: Any) {
Toothpick.inject(target, this)
} |
We've started using a set of custom written extensions that we'd like to make public and incorporate with the toothpick library as a new module. There's a sample project at https://github.com/Leafly-com/toothpick-extensions-sample that has the extension code as well as examples on how it could be used.
Would greatly appreciate feedback. Quick Preview: // Inject with Kotlin Class
scope.getInstance(KotlinClass::class)
// In a Module, bind with Kotlin Class
bind(KotlinClass::class)...
// Inject dependency safely without specifying type via reified types
val dependency: Dependency = inject(scope)
// Lazy inject dependency via delegate
val dependency: Dependency by injectLazy(scope)
// Will inject with Toothpick.openScope(activityRef.application, activityRef)
class MyActivity : Activity() {
private val dependency1: Dependency by inject()
}
// Will inject with lazy provided scope
class MyActivity : Activity() {
private lateinit var lateScope: Scope
private val dependency1: Dependency by inject { scope = lateScope }
...
}
// Binding functions
bind(Dep::class) providedBy DepProvider()
bind(Dep::class) singletonPovidedBy DepProvider::class
bind(Dep::class) named "DepName" providedBy DepProvider()
// DSL
module {
Picasso::class providedBy PicassoProvider::class
} |
We have a shorter inline fun <reified T> Scope.instance(tag: String? = null): T = this.getInstance(T::class.java, tag) val c = scope.instance<MyClass>()
val c1: MyClass = scope.instance() |
@dimsuz Nice! I'll update to to use that pattern. |
This is getting closed as it has been released in version 3.0.0. |
Hi,
Will you guys be adding any Kotlin extensions in the future?
The text was updated successfully, but these errors were encountered: