Kodein-DI 7.0.0(五):依赖注入与检索

2020-08-10  本文已影响0人  何意悲欢0_o

本节中使用的示例:

val di = DI {
    bind<Dice>() with factory { sides:Int -> RandomDice(sides) }
    bind<DataSource>() with singleton { SqliteDS.open("path/to/file") }
    bind<Random>() with provider { SecureRandom() }
    bind<FileAccess>() with factory { path:String,mode:Int -> FileAccess.open(path,mode) }
    constant("answer") with "fourty-two"
}
上一篇 下一篇

猜你喜欢

热点阅读