I need help with the new scope API and the inject ...
# koin
a
I need help with the new scope API and the inject method. Let's assume the following: 1. There is a single
Application
class. 2. Every
Application
holds multiple instances of the
ViewModel
class. 3. Every
View
points to a
ViewModel
where multiple
View
instances can point to the same
ViewModel
. 4. Every
ViewModel
needs to know the
Application
it lives in. 5. Every
View
needs to know the
ViewModel
it should display.
Copy code
class Application

class ViewModel : KoinComponent {
    val application: Application by inject()
}

class View : KoinComponent {
    val viewModel: ViewModel by inject()
}
How do I need to define my module so that the following code runs?
Copy code
val application = koin.get<Application>()
val viewModel = application.scope.get<ViewModel>()
val view = viewModel.scope.get<View>()

assert(application === viewModel.application)
assert(viewModel === view.viewModel)
I get it to work with constructor injection, but not with the
inject
delegate.