1 min read

Daily Dispatch #7 - We march on with KodeIN-DI

Daily Dispatch #7 - We march on with KodeIN-DI

We start the day late, with the errors of yesterday.

e: This version (1.0.0-beta09) of the Compose Compiler requires Kotlin version 1.5.10 but you appear to be using Kotlin version 1.6.0 which is not known to be compatible. Please fix your configuration (or suppressKotlinVersionCompatibilityCheck but don’t say I didn’t warn you!).

All I needed to to was update compose to a version that was compatible with kotlin 1.6.10.

kotlinCompilerExtensionVersion "1.1.0-rc03"

After we replace completely the dependencies for DI from koin to KodeIN-DI, we will go towards mocking.

Koin to KodeIN-DI

class MainActivity : AppCompatActivity() {
    private val demoDataGenerator: DemoDataGenerator by inject()  // KOIN

Now we have:

class MainActivity(di: DI) : AppCompatActivity() {
    private val demoDataGenerator: DemoDataGenerator by di.instance()

Crap, I thought it would be that easy. But it’s not being.

I already added an android kodein library, and a composer-kodein library as well, as the project I’m messing about has jetpack compose.

For some reason that I can’t yet grasp, I can build the project, but it doesn’t change screens or show other values that existed on the Room database.

Now I had to do a few new things.

class MainActivity : BaseActivity() {
    private val demoDataGenerator: DemoDataGenerator by instance()


And

open class BaseActivity() : AppCompatActivity(), DIAware {
    override val di by DI.lazy {
        import(appModule)
        import(storageModule)
    }

}

Also my App composable class became

fun App(di: DI) = withDI(di) {...} 

Which I call using

setContent {
  App(di)
}

The app doesn’t show up the side bar menu, but it creates the test database, so the dependency injection is working.