Hey guys. Noob question. How are we supposed to in...
# koin
t
Hey guys. Noob question. How are we supposed to inject a dependency in a Wasm or Js main.kt ? I've never needed to do it before. The following doesn't seem to work :
Copy code
val getSomeUseCase: GetSomeUseCase = getKoin().get()
Or it should be working but i need to fix something.
a
From compose just use
koinInject
, what is your context?
t
I'm trying to do smth like this :
Copy code
onWasmReady {
        stopKoin()
        KoinHelper().doInitKoin()

        ComposeViewport(
            viewportContainerId = "ComposeTarget"
        ) {
            val getLanguageUseCase: GetLanguageUseCase = koinInject()
I did something similar on JVM but with
= getKoin().get()
instead and it's working. (Also working on Android with some by inject() outside of a composable context.) But i'm starting to wonder if it's not related to the injection of the multiplatform settings lib. I added it only to the common module and i'm not sure that works for all platforms.
Copy code
single<Settings> { Settings() }
Edit: looks like it's related to the settings injection.
a
in compose you should rely on koinInject or koinViewModel
else you might trigger recomposition or unwanted behavior
t
Thanks for the advice. I've refactored accordingly. (And the original issue was related to multiplatform-settings.)
👍 1