简体   繁体   中英

How to apply an annotation to a Koin module dependency declaration?

I have the following Koin module:

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

I need to apply two annotations to RealExampleRepository to supress an experimental coroutines API usage warning.

The annotations I need to apply are:

@FlowPreview
@ExperimentalCoroutinesApi

How can I do this?

I found that it can be done by converting the module to a method and applying the annotations to the method like so:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM