Practically speaking, you probably wouldn't be using
with
as it is mainly just there to set up the scope properly for testing. In a real world example, setting up a Ktor route would have you in multiple nested scopes in which you could set up a function for (e.g. being able to reference both
Application
and
Route
in the same extension function without needing to explicitly pass either instance).
For example, this:
fun doSomething(application: Application, route: Route) { /* ... */ }
could be condensed to:
context(Application, Route)
fun doSomething() { /* ... */ }
And thus the caller would not need to explicitly pass either instance. At least, that is my understanding.