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

Instance injected as factory is resolved by parameter of same type instead of being instantiated with parameter #2124

Open
mathieularue opened this issue Jan 28, 2025 · 0 comments

Comments

@mathieularue
Copy link

Describe the bug
Since Koin 4.0.x, when injecting an instance tagged as a @Factory using the inject function in a KoinComponent, the first parameter of same type is returned instead of being actually passed as a parameter of the requested factory instance (see resolveFromContext() inside the Scope class).

This behaviour started occurring when migrating from 3.x.x to 4.0.x.

To Reproduce

  1. Define a class as a factory using the @Factory annotation
  2. Somewhere inside a KoinComponent, inject the class by providing it a parameter of same type in parametersOf()
  3. Notice that the parameter of same type is returned

Expected behavior
We expect to be able to pass a parameter of same type to a factory instance while still having a new instance created

Koin module and version:
koin-core:4.0.2
koin-annotations:2.0.0-Beta3

Snippet or Sample project to help reproduce

@Factory
class InjectedClass
class Component : KoinComponent {
    val parameter: InjectedClass

    val injected: InjectedClass by inject {
        parametersOf(parameter)
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant