我不知道这是一个错误还是我做错了。我在文档中没有看到任何内容表明应该以除此之外的任何方式调用 kodein 工厂绑定:
class KodeinConfidenceTest {
@Test
fun testThatKodeinWorks() {
val kodein = Kodein {
bind<Dice>() with factory { sides: Int -> RandomDice(sides) }
}
val d:Dice = kodein.instance(5)
}
}
open class Dice
data class RandomDice(val sides:Int) : Dice()
...但这会导致 NotFoundException
com.github.salomonbrys.kodein.Kodein$NotFoundException: No provider found for bind<Dice>("5") with ? { ? }
Registered in Kodein:
bind<Dice>() with factory { Int -> RandomDice }