title: Dagger Hilt how to inject classes into ViewModel
body: <p>I recently started using DI in my project through Dagger Hilt. I'm having no problems when injecting instances into Activities, fragments... etc. But I am not sure how to inject a class instance into ViewModel.</p>
  <p>My approach at the moment consists of adding the classes I need to the constructor of the viewmodel as such:</p>
  <pre><code>class MainViewModel @ViewModelInject constructor(
  application: Application,
  @Named(&quot;classA&quot;) var classA: ClassA,
  @Named(&quot;classB&quot;) var classB: ClassB
  ) : AndroidViewModel(application) 
  </code></pre>
  <p>and then in my AppModule:</p>
  <pre><code>@Module
  @InstallIn(ApplicationComponent::class)
  object AppModule {
  
  @Singleton
  @Provides
  @Named(&quot;ClassA&quot;)
  fun provideClassA(@ApplicationContext context: Context) = ClassA(context)
  
  @Singleton
  @Provides
  @Named(&quot;ClassB&quot;)
  fun provideClassB(@ApplicationContext context: Context) = ClassB(context)
  
  }
  </code></pre>
  <p>Which works great, but ideally and in the case I wanted to add many more instances of other classes, I would prefer doing</p>
  <pre><code>@Inject
  lateinit var classA:ClassA
  </code></pre>
  <p>But I presume this is not possible, as adding @AndroidEntryPoint to the viewModel is not possible, so how are classes injected into viewmodel? or do we just add them to constructor, as in my current solution?</p>