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

Support Lazy Injection #2096

Open
chrisjenx opened this issue Dec 29, 2024 · 0 comments
Open

Support Lazy Injection #2096

chrisjenx opened this issue Dec 29, 2024 · 0 comments

Comments

@chrisjenx
Copy link

Is your feature request related to a problem? Please describe.
Fix for cyclic dependencies, you should be able to use Lazy<T> in constructors, but you'll get: No definition found for type 'kotlin.Lazy'.

Lazy is common use in other DI frame works

Describe the solution you'd like
This is possible manually already, but would be nice of koin supported it via it's singleOf/factoryOf

class ServiceOne(
  val serviceTwo: Lazy<ServiceTwo>
)

class ServiceTwo(
  val serviceOne: Lazy<ServiceOne>,
) 
module {
 factoryOf(::ServiceOne)
 factoryOf(::ServiceTwo)
}

Currently this will fail as Koin will not resolve the Lazy<*> type.

Describe alternatives you've considered

You can work around this limitation doing:

module {
  factory { ServiceOne(inject()) } 
  factory { ServiceTwo(inject()) }
}

You could define a Provider or koin.Lazy type if you wanted to leave the Kotlin one alone.

Target Koin project
koin-core

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