Astronaut4449
02/19/2020, 6:01 PMModel
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>()
arnaud.giuliani
02/20/2020, 8:22 AMarnaud.giuliani
02/20/2020, 8:22 AMAstronaut4449
02/26/2020, 8:36 PMAstronaut4449
02/26/2020, 8:56 PMclass A
class B(val a: A)
val module = module {
factory { A() }
scope<A> {
scoped { B(get()) }
}
}
fun main() {
val koin = startKoin { modules(module) }.koin
val a: A = koin.get()
val b: B = a.scope.get()
println(a === b.a) // false, but true expected
}
How does B get A within its own scope?Astronaut4449
03/05/2020, 4:11 PMarnaud.giuliani
03/05/2020, 4:21 PMarnaud.giuliani
03/05/2020, 4:21 PMarnaud.giuliani
03/05/2020, 4:22 PMval b: B = a.scope.get { parametersOf(a) }
arnaud.giuliani
03/05/2020, 4:22 PMAstronaut4449
03/06/2020, 9:35 PMval a: A = koin.get()
val b: B = a.scope.get()
Astronaut4449
03/06/2020, 9:36 PMarnaud.giuliani
03/07/2020, 10:30 AMarnaud.giuliani
03/07/2020, 10:30 AMscoped { YourClass() }
we are already using the current scopearnaud.giuliani
03/07/2020, 10:30 AMarnaud.giuliani
03/07/2020, 10:31 AM