Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request]Set @InjectedParam values on constructor #148

Open
frankois944 opened this issue Jul 24, 2024 · 0 comments
Open

[Request]Set @InjectedParam values on constructor #148

frankois944 opened this issue Jul 24, 2024 · 0 comments

Comments

@frankois944
Copy link

frankois944 commented Jul 24, 2024

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!

@frankois944 frankois944 changed the title Set @InjectedParam values on constructor [Request]Set @InjectedParam values on constructor Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants