How to use Kodein in KMM?

396 views Asked by At

I have this initializer of Kodein in commonMain module:

@ThreadLocal
object CommonInjector {
    val kodeinContainer = DI.lazy {
        importAll(mainModule)
    }

    val mainModule = DI.Module("main") {
        bind<IAccountManagerGateway>() with singleton { AccountManagerGateway() }
        bind<GetAccountUseCase>() with provider { GetAccountUseCase(instance()) }
        bind<GetDeviceNameUseCase>() with provider { GetDeviceNameUseCase() }
        bind<SignInUseCase>() with provider { SignInUseCase(instance()) }
    }
}

However instance() doesn't work in KMM because of it relies on reified keyword that's not supported by KMM.

How to replace instance() here?

UPD:
Android Studio prints the next error on instance() calls:

'inline fun <reified T : Any> DI.Builder.instance(instance: ???): InstanceBinding<???>' can't be called in this context by implicit receiver. Use the explicit one if necessary
0

There are 0 answers