Hi everyone I am using koin wuth koin-annotations....
# koin
r
Hi everyone I am using koin wuth koin-annotations. Now I am Adding a logger and want to have a factory, that I can pass a tag, that creates a new logger with that tag. This I achieve with the following code:
Copy code
@Factory
fun provideLogger(@InjectedParam tag: String?): Logger {
    return if (tag != null) logger.withTag(tag) else logger
}
Now I am wondering, how I can pass the tag when creating for example a singleton:
Copy code
@Single
class SomeService(logger: Logger) { ... }
Is there any solution to this?
f
CurrentIy, Koin annotation can’t support parameter injection directly, you need to use the dsl way to inject some value
My point is to create a singleton dedicated to inject the value of the tag
something like:
Copy code
object Logger : KoinComponent {
   fun log(tag: String? = null) : Logger {
     return get<Logger>(parameters = { parametersOf(tag) })
   }
}
r
Ok, thanks for your answer. I tried it and did it like this:
Copy code
@Single
class SomeService(
    logger: Logger = getKoin().get<Logger> { parametersOf("SomeService") }
) { ... }
This works fine.