Search code examples
androidkotlindependency-injectionkoin

What is difference between in inject vs viewmodel in Android koin


I'm using Koin 3.2 which has the new module includes feature. I am want to know what is the difference between the use of by inject() or by viewmodel().

val viewModel by inject<MainActivityViewModel>()

or

val viewModel by viewmodel<MainActivityViewModel>()

in viewmodel. I know both works correctly.

Thanks


Solution

  • The difference is by viewmodel will hook to register the instance to your Lifecycle. Where a simple by inject just create the instance