要求:KodeinBinding<in ???, in ???, out TaskRepository>

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

在探索 Kodein 时,我遵循 https://proandroiddev.com/dependency-injection-with-kotlin-kodein-koin-3d783745e48d

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

我收到错误消息

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

怎么了?

仅供参考,我使用 kodeIn 版本 6.4.0

补充一下,我试过 https://kodein.org/di/

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

同样的事情发生了。我做错什么了吗?或者文档已过时?

发现问题。我不小心包括了

import java.util.Collections.singleton

而不是

import org.kodein.di.generic.singleton

这里有一个完整的工作示例:

import org.kodein.di.Kodein
import org.kodein.di.generic.bind
import org.kodein.di.generic.instance
import org.kodein.di.generic.singleton

interface TasksRepository {
    fun log(): String = "EMPTY"
}
class FakeTasksRepository : TasksRepository {
    override fun log(): String = "Hello Kodeiners!"
}

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

fun main() {
    val kodein = Kodein {
        import(diModel)
    }

    val tasksRepository: TasksRepository by kodein.instance()
    println(tasksRepository.log())
}