如何在KMM中使用Kodein?

发布于 2025-01-24 12:30:36 字数 1034 浏览 0 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文