1

As stated in Play Slick documentation a DatabaseConfig object can be obtained via Global Lookup:

val dbConfig = DatabaseConfigProvider.get[JdbcProfile](Play.current)

However I get the following compilation warning stating that current is deprecated and that I should use DI instead:

[warn] C:\myapp\app\test\Test.scala:28: method current in object Play is deprecated: This is a static reference to application, use DI instead

Am I forced to use DI instead of global lookup? With the deprecation warning the database connection works fine.

ps0604
  • 1,227
  • 23
  • 133
  • 330

1 Answers1

1

Either inject actually Play app (and pass it as parameter as you did) or better, inject DatabaseConfigProvider itself - in that way it won't need Application:

@Singleton
class DbAccessPlayConfig @Inject()(dbConfigProvider: DatabaseConfigProvider) {
  val dbConfig = dbConfigProvider.get[JdbcProfile]
}
Paul Dolega
  • 2,446
  • 14
  • 23
  • Can I access dbConfig (the one you defined in the Singleton) from multiple threads? how should concurrency be managed in this case? – ps0604 Dec 02 '16 at 13:11
  • I guess what you do with `DbConfig` most of the times is basically get `db` out of it (which needs to be thread-safe anyway). `db` field is simply `val` inside so it should be safe. – Paul Dolega Dec 02 '16 at 13:27