[Feature request] ContributesAndroidInjector with FragmentFactory lifecycles
See original GitHub issueDaggerFragment used with ContributesAndroidInjector works fine. However, with the introduction of FragmentFactory, field injection is not needed anymore and constructor injection can be used for fragments. While this works fine, subcomponent lifecycle (w.r.t fragment) is missed and in some cases fragment can stay alive even and reused across back stack navigation (within the same activity instance/parent component).
This request to support some kind of scope/life cycle for multibindings used by the fragment factory injector.
Current:
@Module
abstract class FragmentBindingModule {
@ContributesAndroidInjector( modules = [MainFragmentModule::class] )
abstract fun mainFragment() : MainFragment
}
New:
@Module
abstract class FragmentModule {
@Binds
@IntoMap
@FragmentKey( MainFragment::class )
// Associate MainFragmentModule to fragment lifecycle
abstract fun bindMainFragmentFragment( fragment: MainFragment) : Fragment
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7
Top Results From Across the Web
Ian Lake on Twitter: "Thanks for everyone who came to the ...
[Feature request] ContributesAndroidInjector with FragmentFactory ... The real question here is if Fragment loses its own Lifecycle and exists only when it ...
Read more >Constructor injection into Fragments with respect of scopes
To be able to inject scoped dependencies into ConstructorInjectionFragment we need to create a subcomponent of the activity component for this ...
Read more >AndroidX Navigation with Dagger 2 & FragmentFactory
Injecting dependencies into Fragment classes has always been less than ideal (to say the least) when compared to other “regular” classes.
Read more >Using dagger in multi-module apps : r/androiddev - Reddit
ExoPlayer will be usually constrained to a single feature/module, ... Despite all of this, it doesn't require you to learn any Dagger magic ......
Read more >Droidcon Italy: Working with Dagger and Kotlin - Speaker Deck
class GameFragmentFactory : FragmentFactory() { override fun ... dagger.android @ContributesAndroidInjector dagger.dev/dev-guide/android ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In a nutshell, you still need to write subcomponent manually. The approaches to perform cotructor injection on
Fragment
class while still maintain scoping is described here: https://medium.com/@nlg.tuan.kiet/fragmentfactory-and-how-to-maintain-scoping-with-dagger-2-d9d16c892626 Sample project: https://github.com/nlgtuankiet/FragmentFactory@nlgtuankiet, i had tried to implement your code, it’ working fine, but when i want to create a new separate component, it give me error,
https://github.com/nlgtuankiet/todo-sample/issues/2,
Raised the issue, please have a look at it
Please find the project link to reproduce the error, https://github.com/TheReprator/BugReproduceFragmentFactory