InsertKoinIO / koin

Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform
https://insert-koin.io
Apache License 2.0
8.93k stars 710 forks source link

Implicit type resolution #1771

Open peter-kovacs-accedo opened 7 months ago

peter-kovacs-accedo commented 7 months ago

In my project when I want to use get() or inject() functions I have to specify types explicitly, which makes huge overhead in the project.

See PR: https://github.com/InsertKoinIO/koin/pull/1772

For more context: I'm working on a feature based application, where lots of interfaces can be injected with different implementations (only one by each sub-project) and it's handled when a dependency is not present on a given sub-project. When I want to use inject() or get() I'm getting errors like:

No value passed for parameter 'clazz'

Type mismatch (Required:Context Found: Lazy<???>)

None of the following candidates is applicable because of receiver type mismatch etc.

However it's simple to solve.

arnaudgiuliani commented 6 months ago

Is it Java compat extension?

peter-kovacs-accedo commented 6 months ago

No, I'm using those for kotlin. The issue is that Koin cannot resolve types which are coming from other packages.

Before this update I needed to use protected val myService: MyService by inject(MyService::class.java)

With the changes it's enough to call: protected val myService: MyService by inject()

stale[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

peter-kovacs-accedo commented 4 weeks ago

Just checking in, Did you evaluate this PR?