In Dagger 2, Is putting All ViewModels inside AppComponent is the right place.
Because I check this android google sample, All ViewModel scoped in the app component but I think the view model should be in it is view (Activity, Fragment) scope/subcomponent?
something like this:
@ContributesAndroidInjector(modules = [LoginActivityModule::class])
abstract fun contributeLoginActivity() : LoginActivity
-
@Module
abstract class LoginActivityModule {
@Binds
@IntoMap
@ViewModelKey(LoginViewModel::class)
abstract fun bindLoginViewModel(viewModel: LoginViewModel): ViewModel
}
To avoid memory-leak
I need explanation.