I wanted to have @Named qualifier for object that's returned from @Binds method, but I noticed that's only possible through static provides method, which I couldn't figure out in practical implementation. So below is what I wanted to achieve.
I have a custom UserScope, which would contain all activities/fragments/viewModels after user logged in, I have LoginViewModel in AuthViewModelModule and LeadViewModel an other VM in UserViewModelModule both VMModule binds VMProvider.Factory and for that reason I need to have @Named qualifier for the VMFactory instance, so I could inject @Named ones in respective activities/fragments.
@Module
internal abstract class AuthViewModelModule {
@Binds
@IntoMap
@ViewModelKey(LoginViewModel::class)
internal abstract fun bindLoginViewModel(loginViewModel: LoginViewModel): ViewModel
@Binds
internal abstract fun bindViewModelFactory(factory: AuthViewModelFactory):
ViewModelProvider.Factory
}
@Module
internal abstract class UserViewModelModule {
@Binds
@IntoMap
@ViewModelKey(LeadViewModel::class)
internal abstract fun bindLeadViewModel(leadViewModel: LeadViewModel): ViewModel
@Binds
internal abstract fun bindViewModelFactory(factory: UserViewModelFactory):
ViewModelProvider.Factory
}