Search code examples
kotlinkodein

required: KodeinBinding<in ???, in ???, out TaskRepository>


In exploring Kodein, I'm following the example in https://proandroiddev.com/dependency-injection-with-kotlin-kodein-koin-3d783745e48d

val diModel = Kodein.Module {
    bind<TasksRepository>() with singleton {
        FakeTasksRepository()
    }
}

I got the error

Type inference failed. Expected type mismatched:
required: KodeinBinding<in ???, in ???, out TaskRepository>
found:    (Mutable)set<(() -> FakeTaskRepository)!>!

What's wrong?

FYI, I use kodeIn version 6.4.0

Add on, I have tried example from https://kodein.org/di/

val businessModule = Kodein.Module {
    bind<IService>() with singleton { BusinessService() }
}

The same things happen. Did I do something wrong? Or the documentation is out dated?


Solution

  • Found the issue. I accidentally include

    import java.util.Collections.singleton

    instead of

    import org.kodein.di.generic.singleton