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

ScopeFragment stopped working with Koin 2.2.1 #965

Closed
joernahrens opened this issue Nov 27, 2020 · 3 comments
Closed

ScopeFragment stopped working with Koin 2.2.1 #965

joernahrens opened this issue Nov 27, 2020 · 3 comments
Labels
question Usage question

Comments

@joernahrens
Copy link

Describe the bug
I have fragment-scoped modules like this:

scope<MainFragment> {
  scoped {
    SomeDependency(get<MainFragment>())
  }
}

With version 2.2.1, the fragment can't be injected anymore.

To Reproduce

I created a small repo to show this bug: https://github.com/joernahrens/kointest

Steps to reproduce the behavior:

  1. Just check out and run the app from the repository
  2. See the crash

Caused by: org.koin.core.error.NoBeanDefFoundException: No definition found for class:'com.joernahrens.android.kointest.ui.main.MainFragment'. Check your definitions!

Koin doesn't find the fragment instance in the scope.

Expected behavior
It should be able to inject the ScopeFragment instance.

Koin project used and used version (please complete the following information):

    implementation "org.koin:koin-androidx-scope:2.2.1"
    implementation "org.koin:koin-androidx-viewmodel:2.2.1"
    implementation "org.koin:koin-androidx-fragment:2.2.1"

This worked in version 2.2.0.

@Pfoerd
Copy link
Contributor

Pfoerd commented Dec 14, 2020

Hi. The ability to access Fragment as source of your FragmentScope was removed due to a memory leak: #953 .
As your FragmentScope lives longer than your Fragment (configuration changes etc.) it can't be used the way it is in your example.
If you need a scope where you can access the fragment as source i think you should create a custom scope and handle it's lifecycle on your own.

@joernahrens
Copy link
Author

Hi @Pfoerd, I agree with the memory leak problem and stumpled upon that issue, so yeah, it explain why it doesn't work. But my understanding of the scope is different, and I think my expectation matches the documentation.

As your FragmentScope lives longer than your Fragment (configuration changes etc.)

My understanding of activity and fragment scopes was, that they don't survive a configuration change, instead all scoped stuff is recreated. Is this a misunderstanding?

@arnaudgiuliani arnaudgiuliani added the question Usage question label Dec 17, 2020
@joernahrens
Copy link
Author

It seems that version 2.2.2 fixed all my problems (well the koin related problems I had 😉 ). Thank you very much! Closing this..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Usage question
Projects
None yet
Development

No branches or pull requests

3 participants