考虑以下注入器:
class Injector constructor(secretSauce: SecretSauce) {
val kodein = Kodein {
bind<SpicyBeans>() with factory { beans: List<Bean>, herbs: List<Herb> ->
SpicyBeans(secretSauce, beans, herbs)
}
}
}
以及以下业务逻辑:
class TastyMeal {
private lateinit var injector : Kodein
private lateinit var spicyBeans : SpicyBeans
fun initialiseWithInjector(kodein : Kodein) {
injector = kodein
val herbs = listOf(Coriander(), Cumin())
val beans = listOf(Pinto(), BlackEyed())
// fetch SpicyBeans via given Kodein Factory, given herbs and beans here
}
}
如何使用 Kodein 的直接注入功能SpicyBeans
使用工厂获取实例,传入List<Herb>
和实例化List<Bean>
之后 TastyMeal
?我在文档中找不到示例。