InsertKoinIO / koin-annotations

Koin Annotations - About Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform insert-koin.io
https://insert-koin.io
Apache License 2.0
163 stars 44 forks source link

[Request]Set @InjectedParam values on constructor #148

Open frankois944 opened 4 months ago

frankois944 commented 4 months ago

Hi,

Better explaining with an example

Currently, I'm getting the instance of my logger with a custom tag by injecting with @InjectedParam

@Factory
fun getLoggerWithTag(
    @InjectedParam tag: String?,
    loggerConfig: LoggerConfig,
) = Logger(
    config = loggerConfig,
    tag = tag ?: "Shared",
)

@Single
internal class MySingleClass : KoinComponent {
    // setting the tag of my logger with the parameter capabilities
    val logger: Logger = get(parameters = { parameterSetOf("MySingleClass") })
}

As I can't use Koin API in the constructor, I need to declare an extra property to manage the logger parameters.

It is possible to avoid the first case? And doing something like the following example? It will be easier to set default values or override them.

@Single
internal class MySingleClass(
   @InjectingParam(parameters = { parameterSetOf("MySingleClass") })
   val logger: Logger,
)

Thanks!