-
-
Notifications
You must be signed in to change notification settings - Fork 727
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
shouldn't inject parameters when qualifier is present #2090
base: 4.1.0
Are you sure you want to change the base?
Conversation
i also think it's kind of weird that we can't do this: module {
single { "Hello," + it.get<String>() }
}
koin.get<String> { parametersOf("World!") } // never get "Hello,World!", always "World!" when the declared type is same to the parameter and no qualifier presents, the parameter always win. |
I don't understand your point here 🤔 Let avoid mixing topic 👍 |
The key point is the inject order: // code from Scope
private fun <T> resolveFromContext(
instanceContext: ResolutionContext
): T {
return resolveFromInjectedParameters(instanceContext)
?: resolveFromRegistry(instanceContext)
?: resolveFromStackedParameters(instanceContext)
?: resolveFromScopeSource(instanceContext)
?: resolveFromParentScopes(instanceContext)
?: throwNoDefinitionFound(instanceContext)
} If we want to resolve an instance of class module {
single<String> { parameters -> "Hello," + parameters.get<String>() }
}
koin.get<String> { parametersOf("World!") } == "World!" This it the current implement, becase we can't tell which instance is wanted. module {
single<String>(named("echo")) { parameters -> "Hello," + parameters.get<String>() }
}
koin.get<String>(named("echo")) { parametersOf("World!") } // expected "Hello,World!", but currently we get "World!" All in all, I just find a situation where we should skip the parameter injection and continue the rest. |
it's about how you shadow your definition instances. The latest additions in your context show be found first. If you try to pass an instance T in the parameters, you will solve this param first as it's the most recent additions. If you use qualifier, it won't find it in the parameters as it doesn't have been tagged with qualifier. |
@arnaudgiuliani exactly, but the parameter injection doesn't check the qualifier, only the type: private inline fun <T> resolveFromInjectedParameters(ctx: ResolutionContext): T? {
return if (ctx.parameters == null) null
else {
_koin.logger.debug("|- ? ${ctx.debugTag} look in injected parameters")
ctx.parameters.getOrNull(clazz = ctx.clazz)
}
} |
I see your point, we could skip parameter stage if we have qualifier 👍 |
example:
PS. this issue will effect multibinding with parameters:
multibinding #1951