title: Injecting ViewModelFactory in different activities
body: <p>I'm using the well-known Dagger-ViewModelFactory pattern to be able to inject a factory for all the <code>ViewModel</code> in all the activities.</p>
  
  <pre><code>@ActivityScope
  class ViewModelFactory @Inject constructor(
      private val creators: MutableMap&lt;Class&lt;out ViewModel&gt;, @JvmSuppressWildcards Provider&lt;ViewModel&gt;&gt;
  ) : ViewModelProvider.Factory {
  
      override fun &lt;T : ViewModel&gt; create(modelClass: Class&lt;T&gt;): T {
          val creator = creators[modelClass] ?: creators.entries.firstOrNull {
              modelClass.isAssignableFrom(it.key)
          }?.value ?: throw IllegalArgumentException("unknown model class $modelClass")
          return creator.get() as T
      }
  }
  
  </code></pre>
  
  <p>The problem I have is that when I inject the factory into an <code>Activity</code> Dagger fails because the providers of the objects for the <code>ViewModels</code> that I'm not going to use are not always accessible. They are not because the modules that contain the providers have not been added.</p>
  
  <p>For example, I have a <em>LogIn</em> activity and a <em>SignUp</em> activity, and this is the way I add the subcomponents for them:</p>
  
  <pre><code>    @ContributesAndroidInjector(modules = [
          ViewModelModule::class,
          FirebaseModule::class,
          LogInModule::class,
          BindLogInModule::class
      ])
      @ActivityScope
      internal abstract fun loginActivityInjector(): LoginActivity
  
      @ContributesAndroidInjector(modules = [
          ViewModelModule::class,
          FirebaseModule::class,
          SignUpModule::class,
          BindSignUpModule::class
      ])
      @ActivityScope
      internal abstract fun signUpActivityInjector(): SignUpActivity
  </code></pre>
  
  <p>Please notice that when I create the subcomponent for <code>SignUpActivity</code> I do not add the Module <code>LogInModule</code> because I do not need the bindings in that Module.
  The result is that I get the error</p>
  
  <blockquote>
    <p>e: com.package.my.AppComponent.java:8: error: [Dagger/MissingBinding] com.package.my.login.domain.LogInAuthenticator cannot be provided without an @Provides-annotated method.
    public abstract interface AppComponent extends dagger.android.AndroidInjector {
                    ^
      A binding with matching key exists in component: com.package.my.di.ActivityInjectorsModule_LoginActivityInjector$app_prodDebug.LoginActivitySubcomponent
          com.package.my.login.domain.LogInAuthenticator is injected at
              com.package.my.login.repository.LoginRepository(logInAuthenticator)
          com.package.my.login.repository.LoginRepository is injected at
              com.package.my.login.domain.LoginUseCase(loginRepository)
          com.package.my.login.domain.LoginUseCase is injected at
              com.package.my.login.presentation.LoginViewModel(loginUseCase)
          com.package.my.login.presentation.LoginViewModel is injected at
              com.package.my.di.ViewModelModule.provideLoginViewModel(viewModel)
          java.util.Map,javax.inject.Provider> is injected at
              com.package.my.di.ViewModelFactory(creators)
          com.package.my.di.ViewModelFactory is injected at
              com.package.my.di.ViewModelModule.bindViewModelFactory$app_prodDebug(factory)
          androidx.lifecycle.ViewModelProvider.Factory is injected at
              com.package.my.login.ui.SignUpActivity.viewModelFactory
          com.package.my.login.ui.SignUpActivity is injected at
              dagger.android.AndroidInjector.inject(T) [com.package.my.di.AppComponent → com.package.my.di.ActivityInjectorsModule_SignUpActivityInjector$app_prodDebug.SignUpActivitySubcomponent]</p>
  </blockquote>
  
  <p>This happens because <code>LogInAuthenticator</code> is provided by <code>LogInModule</code>.</p>
  
  <p>Does this mean that the only solution is to add <code>LogInModule</code> even if I don't really need to create <code>GoogleSignInClient</code> in the <code>SignUpActivity</code>?</p>