I am using ViewModel savestate handle in my app, I inject ViewModel using the dagger, So I used AssistInject to inject SaveStateHandle
in to viewmodel. Everything works fine for me, But one thing I need to know is that I need to pass the bundle which I received in the fragment to the savestatehandle. So in my fragment module, I provide the method injection for the fragment/activity which am using and get the arguments/intent and so while using the scope I can get the same bundle in the viewmodel factory.
Example: Dagger Fragment/Activity module class
@FragmentScope
@ContributesAndroidInjector(modules = [TestingModule::class])
abstract fun bindTestingScreenFragment(): TestingScreen
TestingModule::class
@Module(includes = [TestingModule.TestingAbstractModule::class])
class TestingModule {
@Provides
fun provideDefaultArgs(testingScreen: TestingScreen): Bundle? = testingScreen.arguments
@Module
abstract class TestingAbstractModule {
@Binds
abstract fun bindTestingScreen(testingScreen: TestingScreen): SavedStateRegistryOwner
}
}
The doubt which i had is in the provideDefaultArgs
method i inject the screen which i am currently injecting for, So how this works without the circular dependency error. does anyone have any idea on this ?