chi
09/27/2021, 10:01 AMclass Cache(sess: SessionManager)
class MyViewModel(cache: Cache): ViewModel {}
module {
single { SessionManager() }
scope(named("userSession")) {
scoped { Cache(get()) }
viewModel { MyViewModel(get()) }
}
}
class MyFragment: Fragment() {
private val myVm: MyViewModel by viewModel()
}
The above is the structure of my koin setup but when I run this it crashes my app with the error;
Caused by: org.koin.core.error.NoBeanDefFoundException: No definition found for class:'com.play.MyViewModel'. Check your definitions!
Please what could I be doing wrongly here?arnaud.giuliani
09/27/2021, 10:29 AMprivate val myVm: MyViewModel by viewModel()
is requesting your viewModel from global space, but you defined it in a scopearnaud.giuliani
09/27/2021, 10:29 AMarnaud.giuliani
09/27/2021, 10:30 AMarnaud.giuliani
09/27/2021, 10:31 AMval userSession : Scope by lazy { getKoin().getOrCreateScope( ... )}
arnaud.giuliani
09/27/2021, 10:31 AMprivate val myVm: MyViewModel by userSession.viewModel()
chi
09/27/2021, 10:38 AMviewModel
method requires which I have no idea how to obtain. You have any example of this?chi
09/27/2021, 11:28 AMprivate val viewModel: MyViewModel by userScopeSession.viewModel(owner = { ViewModelOwner(viewModelStore) })
arnaud.giuliani
09/27/2021, 12:06 PMchi
09/27/2021, 12:19 PMarnaud.giuliani
09/27/2021, 12:40 PM