Open fleficher opened 3 months ago
On Koin 3.5.6
I am getting the same error
Caused by org.koin.core.error.NoParameterFoundException: Can't get injected parameter #0 from DefinitionParameters[] for type 'xxx'
and I am also using an Activity
with AndroidScopeComponent
but I am not using ViewModel
and activityRetainedScope()
.
I could reproduce de error with this test on the Koin lib:
class ScopeWithParametersTest : AutoCloseKoinTest() {
interface MyContract {
interface View
interface Presenter
}
class MyView : AppCompatActivity(), AndroidScopeComponent, MyContract.View {
override val scope by lazy { getKoin().getScopeOrNull(getScopeId()) ?: getKoin().createScope(getScopeId(), getScopeName(), this) }
// It also breaks with activityRetainedScope:
// override val scope by activityRetainedScope()
}
class MyPresenter(private var view: MyContract.View?) : MyContract.Presenter
interface FacadeContract
class MyFacade(private var presenter: MyContract.Presenter?) : FacadeContract
object MyModule {
val instance = module {
scope(named<MyView>()) {
scoped<FacadeContract> {
MyFacade(presenter = get())
}
scoped<MyContract.Presenter> { (view: MyContract.View) ->
MyPresenter(view = view)
}
}
}
}
@get:Rule
val mockProvider = MockProviderRule.create { clazz ->
mockkClass(clazz)
}
@Test
fun `check koin definitions with success`() {
startKoin {
modules(
MyModule.instance
)
}.checkModules()
}
}
I think the problem is something related to classes with parameters inside scopes.
I could test scoped object to activity, injected in shared VM: https://github.com/InsertKoinIO/koin/commit/9902222e93cdadb3cb86fb161ee52a87e39ed681
@fleficher can you test upgrade to 3.5.6?
Hi @arnaudgiuliani , I confirm that I don't experience the crash anymore using version 3.5.6 👍 Thanks!
Describe the bug
When a shared ViewModel that has parameters gets injected in a Fragment, Koin fails to retrieve the instance:
It seems to happen if the activity is implementing
AndroidScopeComponent
withactivityRetainedScope()
scope.Koin module and version:
koin-android:3.5.3
koin-core:3.5.3
was working well on
3.5.0
Snippet or Sample project to help reproduce