Paul Woitaschek

07/17/2022, 5:46 AM
I’m have a composable that creates a scoped dagger component and fetches several dependencies from it. In order for my code to work correctly, this scope would need to survive configuration changes. As a solution I’ve hacked my dagger component to be retained by the ViewModelStore. Does this make sense or is there a better way to retain objects at this point?
class HoldingViewModel : ViewModel() {
  val values = mutableMapOf<Class<*>, Any>()

inline fun <reified T : Any> viewModelStoreRemembered(
  crossinline create: () -> T
): T {
  val map = viewModel(
    modelClass =,
  return map.getOrPut( {
  } as T