【问题标题】:How to apply an annotation to a Koin module dependency declaration?如何将注释应用于 Koin 模块依赖声明?
【发布时间】:2019-09-11 15:41:18
【问题描述】:

我有以下 Koin 模块:

val exampleModule = module {
    single<ExampleRepository> { RealExampleRepository() }
}

我需要对RealExampleRepository 应用两个注释来抑制实验性协程 API 使用警告。

我需要应用的注释是:

@FlowPreview
@ExperimentalCoroutinesApi

我该怎么做?

【问题讨论】:

    标签: android kotlin kotlin-coroutines koin


    【解决方案1】:

    我发现可以通过将模块转换为方法并将注释应用于方法来完成,如下所示:

    @FlowPreview
    @ExperimentalCoroutinesApi
    fun exampleModule() = module {
        single<ExampleRepository> { RealExampleRepository() }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-08
      相关资源
      最近更新 更多