如何在KMM中使用Kodein?
我在 kodein commonmain 模块中具有此初始化器:
@ThreadLocal
object CommonInjector {
val kodeinContainer = DI.lazy {
importAll(mainModule)
}
val mainModule = DI.Module("main") {
bind<IAccountManagerGateway>() with singleton { AccountManagerGateway() }
bind<GetAccountUseCase>() with provider { GetAccountUseCase(instance()) }
bind<GetDeviceNameUseCase>() with provider { GetDeviceNameUseCase() }
bind<SignInUseCase>() with provider { SignInUseCase(instance()) }
}
}
但是instance()
在KMM中不起作用,因为它依赖于repied
KMM不支持的关键字。
如何在此处替换实例()
?
upd:
Android Studio 在instance()
呼叫上打印下一个错误:
'inline fun <reified T : Any> DI.Builder.instance(instance: ???): InstanceBinding<???>' can't be called in this context by implicit receiver. Use the explicit one if necessary
I have this initializer of Kodein in commonMain module:
@ThreadLocal
object CommonInjector {
val kodeinContainer = DI.lazy {
importAll(mainModule)
}
val mainModule = DI.Module("main") {
bind<IAccountManagerGateway>() with singleton { AccountManagerGateway() }
bind<GetAccountUseCase>() with provider { GetAccountUseCase(instance()) }
bind<GetDeviceNameUseCase>() with provider { GetDeviceNameUseCase() }
bind<SignInUseCase>() with provider { SignInUseCase(instance()) }
}
}
However instance()
doesn't work in KMM because of it relies on reified
keyword that's not supported by KMM.
How to replace instance()
here?
UPD:
Android Studio prints the next error on instance()
calls:
'inline fun <reified T : Any> DI.Builder.instance(instance: ???): InstanceBinding<???>' can't be called in this context by implicit receiver. Use the explicit one if necessary
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论