Skip to content

Instantly share code, notes, and snippets.

@cvogt
Last active October 9, 2016 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cvogt/029c91231b8c75729722c5672fe2dfd4 to your computer and use it in GitHub Desktop.
Save cvogt/029c91231b8c75729722c5672fe2dfd4 to your computer and use it in GitHub Desktop.
decoupled configuration code structure
object Application{
def run(config: Config): Unit = {
val db = connectToDb( config.dbHost, config.dbPort )
...
}
}
case class Config(
dbHost: String,
port: Int
)
object ProductionConfig{
def main(args: Array[String]): Unit = {
Application.run( Config("db.production-server.com",12345) )
}
}
object TestConfig{
def main(args: Array[String]): Unit = {
Application.run( Config("db.test-server.com",10000) )
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment