Last active
December 12, 2015 01:48
-
-
Save stephanos/4693853 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Library | |
// ================================================= | |
trait ConfigComp { | |
trait Config { | |
def get(k: String): String | |
} | |
def config: Config | |
} | |
trait QueueComp { | |
self: ConfigComp => | |
class Queue { | |
val key = config.get("some-key") | |
} | |
lazy val queue = new Queue | |
} | |
// Application | |
// ================================================= | |
object MyConfig extends ConfigComp { | |
val config = new Config { | |
println("INITIALIZING CONFIG") | |
def get(k: String) = "value" | |
} | |
} | |
trait MyConfig extends ConfigComp { | |
lazy val config = MyConfig.config | |
} | |
object Frontend extends QueueComp with MyConfig | |
object Backend extends QueueComp with MyConfig | |
Frontend.queue.key | |
Backend.queue.key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[error] overriding method config in trait ConfigComp of type => MyConfig.this.Config; | |
[error] lazy value config has incompatible type | |
[error] lazy val config = MyConfig.config | |
[error] ^ | |
[error] one error found |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if you nest Config in ConfigComp, it should work by doing this:
search for path-dependent types for more info.