Created
May 2, 2016 22:48
-
-
Save eishay/2f25c07f0b8b132c2d03e0fb64ff1e7b 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
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