title: Dagger Hilt - How do I inject the ViewModel into the Adapter?
body: <p>I am trying to inject the ViewModel into the adapter. It works fine while injecting into Fragment.</p>
  <p><strong>ViewModel:</strong></p>
  <pre><code>class HomeViewModel @ViewModelInject constructor(
  ): ViewModel() 
  </code></pre>
  <p><strong>Fragment:</strong></p>
  <pre><code>@AndroidEntryPoint
  class HomeFragment : BaseFragment&lt;FragmentHomeBinding, HomeViewModel&gt;(
  R.layout.fragment_home
  ) {
  
  private val viewModel: HomeViewModel by viewModels()
  </code></pre>
  <p>There is no problem so far. But problems arise when I try to inject into the adapter.</p>
  <pre><code>class HomeListAdapter @Inject constructor(
  ): BaseListAdapter&lt;Users&gt;(
  itemsSame = { old, new -&gt; old.username == new.username },
  contentsSame = { old, new -&gt; old == new }
  ) {
  
  
  
  private val viewModel: HomeViewModel by viewModels() //viewModels() unresolved reference
  </code></pre>
  <p><a href="https://i.stack.imgur.com/24QnW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/24QnW.png" alt="enter image description here" /></a></p>
  <p><strong>UPDATE:</strong></p>
  <p>If I try to use constructor injection or field injection I get the following error:</p>
  <pre><code>  error: [Dagger/MissingBinding] ***.home.HomeViewModel cannot be       provided without an @Inject constructor or an @Provides-annotated method.
    public abstract static class ApplicationC implements App_GeneratedInjector,
                           ^
        ***.home.HomeViewModel is injected at
            ***.home.adapter.HomeListAdapter.viewModel
        ***.home.adapter.HomeListAdapter is injected at
            ***.home.HomeFragment.viewAdapter
        ***.home.HomeFragment is injected at
                       ***.home.HomeFragment_GeneratedInjector.injectHomeFragment(***.home.HomeFragment) [***.App_HiltComponents.ApplicationC →    ***.App_HiltComponents.ActivityRetainedC → ***.App_HiltComponents.ActivityC → ***.App_HiltComponents.FragmentC]
  </code></pre>
  <p><strong>Adapter:</strong></p>
  <pre><code>class HomeListAdapter @Inject constructor(
  ): BaseListAdapter&lt;Users&gt;(
  itemsSame = { old, new -&gt; old.username == new.username },
  contentsSame = { old, new -&gt; old == new }
  ) {
  
  
  @Inject lateinit var viewModel: HomeViewModel;
  </code></pre>