https://kotlinlang.org logo
#koin-contributors
Title
# koin-contributors
h

henrikhorbovyi

06/30/2020, 3:41 PM
Hey everyone... I'd like to see what you think about it. I share the same idea, that's why I'm sending it here 🙂
@Sean McQuillan [G] I'd just add just a lazy return.
Copy code
@Composable
inline fun <reified T> inject(): Lazy<T>{
    val context = GlobalContext.get().koin
    return remember(context) { context.inject() }
}
So, I'd call 😀
Copy code
val repository: Repository by inject()
Instead of
Copy code
val repository: Repository = inject()
s

Sean McQuillan [G]

06/30/2020, 6:45 PM
Makes sense and matches the local delegate usage pattern of state / mutableStateOf in compose.
Is the context guaranteed to never change?
If so, this would be slightly more performant:
Copy code
/ ...
return remember {
    val context = ...
    context.inject()
}
✔️ 1
h

henrikhorbovyi

06/30/2020, 6:53 PM
Good one. GlobalContext is an
object
so I suppose it won't change
a

arnaud.giuliani

07/01/2020, 7:03 AM
Yes, Default Koin context won’t change, no problem 👍
could be interesting to have a
koin-androidx-compose
sub project then, gathering the needed extensions
🤘 1
h

henrikhorbovyi

07/01/2020, 10:46 AM
Really cool. I can prepare a PR 🙂
💯 1