Skip to content

Instantly share code, notes, and snippets.

@eishay
Created May 2, 2016 22:48
Show Gist options
  • Save eishay/2f25c07f0b8b132c2d03e0fb64ff1e7b to your computer and use it in GitHub Desktop.
Save eishay/2f25c07f0b8b132c2d03e0fb64ff1e7b to your computer and use it in GitHub Desktop.
trait DbInfo {
def database: SlickDatabase
def driverName: String
}
class SlickModule(dbInfo: DbInfo) extends ScalaModule {
def configure(): Unit = {
//see http://stackoverflow.com/questions/6271435/guice-and-scala-injection-on-generics-dependencies
lazy val db = dbInfo.driverName match {
case MySQL.driverName => new MySQL(dbInfo.database)
case H2.driverName => new H2(dbInfo.database)
}
bind[DataBaseComponent].toInstance(db)
bind[Database].in(classOf[Singleton])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment