What is the correct way to inject ? ```val analyt...
# koin
d
What is the correct way to inject ?
Copy code
val analytics = koinInject<Analytics>()
or something like:
Copy code
val analytics = koin.get<Analytics>()
I think I saw some other APIs as well, it's a bit confusing. Secondly, why there is: startKoinApplication {} - works in common code too and startKoinApplicationMP {} -works in common code too and startKoin{} and other APIs - again it makes things confusing.
I forgot to mention
Copy code
KoinComponent, with: by inject()
Alright, startKoinApplicationMP is marked as library internal use only
m
Isn’t
koinInject
only for compose?
d
I work in a compose project yes I come from SpringBoot, the dependency injection style there looks the same whatever it’s a service, repository, another lib etc In Compose: koin<>.get() also works Why would create a new method?
There is yet another way with koin: annotations
m
koinInject()
includes the
remember
Copy code
@Composable
inline fun <reified T> koinInject(
    qualifier: Qualifier? = null,
    scope: Scope = currentKoinScope()
): T {
    return remember(qualifier, scope) {
        scope.get(T::class, qualifier)
    }
}
d
Would be better if the name contained Remember as well
👍 2