Hi! I have a construct like this: ``` class Clie...
# announcements
j
Hi! I have a construct like this:
Copy code
class Client {
    fun addHeader(context: Context): Client {
        // adds request headers from the context
        return this
    }

    fun getMethod(name: String) {
        println(name)
    }
}

typealias Context = Any
private val HttpContext = "some-stuff"

class ServiceFooFactory {
    private val baseClinet = Client()

    fun createServiceFoo(context: Context): ServiceFoo {
        return ServiceFoo(baseClinet.addHeader(context))
    }

    class ServiceFoo(private val enhancedClient: Client) {
        fun hello(name: String) {
            enhancedClient.getMethod(name)
        }
    }
}

fun main(args: Array<String>) {
    val factory = ServiceFooFactory()

    factory.createServiceFoo(HttpContext).hello("Bar")
}
Which is working fine. Although I am asking myself if there is a neat way to do a DSL like thing. To achieve something like this:
Copy code
factory.withContext { context ->
    hello("Bar")
}