raulraja
11/07/2017, 2:57 PMinterface Context<A> {
fun A.config(): Config
}
package prod
object ProdContext: Context<Service> {
fun Service.config(): Config = ProdConfig
}
package test
object TestContext: Context<Service> {
fun Service.config(): Config = TestConfig
}
package prod
service.config() // ProdConfig
package test
service.config() // TestConfigdave08
11/14/2017, 8:48 PMraulraja
11/14/2017, 10:50 PMconfig()dave08
11/15/2017, 3:02 AMraulraja
11/16/2017, 3:45 PMContext behavior to all Service types.raulraja
11/16/2017, 3:45 PMconfig() returns ProdConfig if you import the test instance it returns instad TestConfigdave08
11/16/2017, 4:21 PMraulraja
11/16/2017, 5:25 PMdave08
11/16/2017, 5:29 PMtype classes? The `object`s already exist in the lang., maybe you mean type object ProdContext: Context<Service>?raulraja
11/16/2017, 7:46 PMraulraja
11/16/2017, 7:46 PMraulraja
11/16/2017, 7:46 PMraulraja
11/16/2017, 7:46 PMraulraja
11/16/2017, 7:48 PMfun <A> config(): Config given Context<A> = A.config()raulraja
11/16/2017, 7:49 PMconfig<ProdService>() //compiles
config<TestService>() //compiles
config<CloudService>() //does not compile because no `Context<CloudService>()` is found in scope.raulraja
11/16/2017, 7:49 PMraulraja
11/16/2017, 7:50 PMraulraja
11/16/2017, 7:50 PMraulraja
11/16/2017, 7:51 PMdave08
11/16/2017, 8:45 PMraulraja
11/16/2017, 8:48 PM