```val localViewModelStoreOwner = LocalViewModelSt...
# compose-destinations
s
Copy code
val localViewModelStoreOwner = LocalViewModelStoreOwner.current
DestinationsNavHost(
    navController = navController,
    navGraph = NavGraphs.home,
    dependenciesContainerBuilder = {
        dependency(hiltViewModel<HomeViewModel>(localViewModelStoreOwner!!))
    }
)
Copy code
DestinationsNavHost(
    navController = navController,
    navGraph = NavGraphs.home,
    dependenciesContainerBuilder = {
        dependency(hiltViewModel<HomeViewModel>(LocalViewModelStoreOwner.current!!))
    }
)
Why do these 2 snippets behave differently? First one gives us the same instance of viewmodel to work with The Second one returns us a new instance of the viewmodel everywhere its required Is this intended behavior or a bug?
r
Intended. CompositionLocal is overridden before calling Destination composables to be the NavBackStackEntry (done by official library, not by compose destinations). DependencyContainerBuilder is called in that same context, just before calling your Composable with those dependencies.
Above NavHost, it probably defaults to the Activity or to another NavBackStackEntry if you’re doing this inside a Destination of another NavHost.
s
Interesting, Thanks for that @Rafael Costa. I need to dig deeper in CompositionLocal and how the providers work