Is there a way to tie a scope to an instance instead of a string identifier (anonymous scope)?
Let's assume I have a
Model
class, a
Controller
class and a
View
class. There can be several instances of
Model
in the application (scoped), but every one of these models has exactly one
Controller
(scoped). Furthermore it shall be possible to have multiple instances of
View
pointing to a pair of
Model
and
Controller
.
Afaik you can only tie a scope to a scope-id (string)
koin.createScope<Model>(scopeId = "I have to provide an id")
.
koin.createScope<Model>()
works, but only once since it is creating a scope-id from the class name. I want a scope to be bound to an instance. Is that somehow possible? I would love to see an API like this:
val scope1 = koin.createScope<Model>() // idea: scope should be tied to an instance of 'Model' instead of scopeId
val model1 = scope1.get<Model>() // scoped
val controller1 = scope1.get<Controller>() // scoped
val view11 = scope.get<View>() // factory
val view12 = scope.get<View>()
val scope2 = koin.createScope<Model>() // should create another scope tied to another instance of 'Model'
val model2 = scope1.get<Model>() // scoped
val controller2 = scope1.get<Controller>() // scoped
val view21 = scope.get<View>() // factory
val view22 = scope.get<View>()