I haven’t looked much at Scopes, so I’ll have to check that out. Thanks!
s
streetsofboston
02/26/2018, 3:55 PM
You’re welcome. 🙂
Create an
object
that implements your custom Scope and use that for your dependency definitions. Then access that
object
to ‘clear it out’ when needed.
streetsofboston
02/26/2018, 3:55 PM
(not sure if messing with a ‘mutable’ Scope is the official or desired way to do this, but it works for me)
j
Joe
02/26/2018, 3:56 PM
Can you clarify “access the `object`“? Do you mean delete it?
s
streetsofboston
02/26/2018, 4:02 PM
In your dependency definitions, use the
myScope
as the Scope for the dependencies you’d like to be able to throw away.
Copy code
object myScope: Scope<SomeContext> {
override fun getRegistry(context: SomeContext): ScopeRegistry {
...
}
fun clear() {
...
}
}
And when you want to ‘throw it away’ call
clear
.
Copy code
myScope.clear()
j
Joe
02/26/2018, 4:03 PM
Ah okay, now I see. That looks like exactly what I want. Thanks!
s
streetsofboston
02/26/2018, 5:06 PM
Note that you can also use a
ConfigurableKodein
and re-create your dependencies (that is what I use for running unit-tests).
Also, consider using plain `Scope`s or tags if you need to get a different dependency (singleton) given a different context of your app.
The hack of ‘clearing’ your Scope is just that, a hack… 🙂