我有一个范围
scope<MyObject> {
scoped { Presenter() }
}
然后当我得到演示者时,这有效。
val presenter = myObject.scope.get<Presenter>(Presenter::class.java)
同样,当我可以分配一个范围变量时,然后获取演示者。
val myScope = myObject.scope
val presenter = myScope.get<Presenter>(Presenter::class.java)
如果我们关闭它,这仍然可以
val presenter = myObject.scope.get<Presenter>(Presenter::class.java)
myObject.scope.close()
val presenter2 = myObject.scope.get<Presenter>(Presenter::class.java)
但是,如果我分配给另一个范围变量并关闭它,它将失败。
val myScope = myObject.scope
val presenter = myScope.get<Presenter>(Presenter::class.java)
myScope.close()
val presenter2 = myScope.get<Presenter>(Presenter::class.java) // Crash here.
同样,如果我这样做,它也会崩溃
val myScope = myObject.scope
val presenter = myScope.get<Presenter>(Presenter::class.java)
myScope.close()
myScope.getOrCreateScope() // Crash here
val presenter2 = myScope.get<Presenter>(Presenter::class.java)
我明白了close()
,范围不能再提供presenter
了。我就是不明白为什么之后myObject.scope.close()
,myObject.scope
还能提供presenter?(和同一个主持人)
val presenter = myObject.scope.get<Presenter>(Presenter::class.java)
myObject.scope.close()
val presenter2 = myObject.scope.get<Presenter>(Presenter::class.java)
// presenter1 == presenter2