I am trying to initialize my viewModel in Fragment by using sharedViewModel() method, but got NoBeanDefFoundException. Before I initialized it by using activityViewModel() method, but because of new argument in viewmodel constructor and due to the scope, I decided to use exactly sharedViewModel(), which cause the exception in my application. I have no idea, why my Koin can not create instance for my ViewModel, cause almost all code is the same as in previous application, where I used same methods and where all staff is working ok. I will leave here some code below and my exception.
How I started Koin framework
startKoin {
androidContext(this@App)
// declare modules
modules(
...
viewModels, // this is my koin module for viewmodels
...
)
}
My Koin module
val viewModels = module {
viewModel { RegistrationViewModel(get()) }
...
}
My ViewModule itself and the fragment that is use it
class RegistrationViewModel(
private val receiveInviteUseCase: ReceiveInviteUseCase
): BaseViewModel() {
// fragment
class RegistrationFragment: AuthBaseFragment<RegistrationFragmentBinding>(RegistrationFragmentBinding::inflate) {
private val vm: RegistrationViewModel by sharedViewModel()
}