title: How to use NavController in compose ViewModel via hilt
body: <p>I am using jetpack compose with the navigation compose library to navigate from one screen to the next. Usually you would have a <code>ViewModel</code> that would take care of user interactions (e.g.: <code>viewModel.addItem()</code>). In order to fulfill the addItem command i would like to show another screen via <code>navController.navigate()</code>. The <code>ViewModel</code> itself is injected into the Composable via <code>hiltNavGraphViewModel()</code>.</p>
  <p>Now the question is: How could i inject the <code>NavController</code> into the <code>ViewModel</code> via hilt?</p>
  <pre class="lang-kotlin prettyprint-override"><code>@HiltViewModel
  class ScreenViewModel @Inject constructor(
    private val navController: NavController // where does it come from?
  ) : ViewModel() {
  
    fun addItem() {
      navController.navigate(&quot;add-item-screen&quot;)
    }
  
  }
  </code></pre>
  <p>The <code>NavController</code> is created via the <code>rememberNavController()</code> method up in the composable hirarchy. I also do not want to pass the controller down the composable hierarchy or use a CompositionLocal. The preferred approach would be to have the controller available in the ViewModel.</p>