I am trying to use play-slick
plugin to interact with a mySQL
database. Everything works as expected other than a [warn]
I get everytime I compile the code.
On this line: val dbConfig = DatabaseConfigProvider.get[JdbcProfile](Play.current)
The warning is: method current in object Play is deprecated: This is a static reference to application, use DI instead
.
I have tried adding the inject() method with by defining Configuration using dependency injection but it's not working! How do I use the Dependency Injection
in the following code so that I don't have to use Play.current
which has bee deprecated since Play 2.5
import play.api.Play
import play.api.db.slick.DatabaseConfigProvider
import scala.concurrent.Future
import slick.driver.JdbcProfile
import slick.driver.MySQLDriver.api._
import scala.concurrent.ExecutionContext.Implicits.global
case class User(
id: Long,
firstName: String,
lastName: String,
mobile: Long,
email: String
)
class UserTableDef(tag: Tag) extends Table[User](tag, "users") {
def id = column[Long]("id", O.PrimaryKey,O.AutoInc)
def firstName = column[String]("first_name")
def lastName = column[String]("last_name")
def mobile = column[Long]("mobile")
def email = column[String]("email")
override def * =
(id, firstName, lastName, mobile, email) <>(User.tupled, User.unapply)
}
object Users {
val dbConfig = DatabaseConfigProvider.get[JdbcProfile](Play.current) //<-- PROBLEM
val users = TableQuery[UserTableDef]
def get(id: Long): Future[Option[User]] = {
dbConfig.db.run(users.filter(_.id === id).result.headOption)
}
}