I'm moving my Android App that uses Compose to a K...
# koin
d
I'm moving my Android App that uses Compose to a KMP and am stuck at KOIN setup, is there a good go-to example that deals with Context injection and room instantiation in a KMP project with compose?
b
You can check out this project here: https://github.com/joreilly/FantasyPremierLeague
❤️ 1
a
I've updated the getting started for CMP apps if you want: https://insert-koin.io/docs/quickstart/cmp
❤️ 2
d
I am having difficulty understanding how koin init() is being shared between android ios and main, this is not described in detail anywhere so maybe it's too simple. I also found a youtube video which seems to pass the context by calling koin.init() from Android passing the context as an argument. I'll try to follow that guide tomorrow see if it works:

https://www.youtube.com/watch?v=5qc24AQ6ktc

b
This is exactly what you need to do what is described in the video. You always need to initilized Koin for every platform that you are working for anyway, and you can give yourself a possibility to inject platform based components directly from your native platform project that way. For Android this happens in Application class and you should basically extend your existing Koin setup in those areas:
Copy code
fun initKoin(targetModule: Module = module { })
in video is
Copy code
fun initializeKoin(config: (KoinApplication.() -> Unit)? = null)
And then you just call in your application class this method like this:
Copy code
initKoin(
    targetModule = module {
        single<Context> { this@MyApplication } // or androidContext(this@MyApplication)
    }
)
or like he did in the video:
Copy code
initializeKoin {
    androidContext(this@MyApplication)
}
Ping me if something won’t work for you and we can take a look.