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 - Constructor DSL #2096

Open
chrisjenx opened this issue Dec 29, 2024 · 1 comment
Open

Support Lazy Injection - Constructor DSL #2096

chrisjenx opened this issue Dec 29, 2024 · 1 comment

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

@arnaudgiuliani
Copy link
Member

Constructor DSL won't be able to handle that directly. It's a known limitation. We need to wait for work on new generation DSL

@arnaudgiuliani arnaudgiuliani changed the title Support Lazy Injection Support Lazy Injection - Constructor DSL Jan 16, 2025
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