I have started using MacWire for the dependency injection of my Play app, and I am having problems trying to inject the database connection.
Before using DI, my code looked like this:
DB.withConnection { implicit connection =>
...
}
This is not working anymore after using DI. I get the following exception: java.lang.InstantiationException: play.api.db.DBApi
.
My application loader:
class Loader extends ApplicationLoader {
def load(context: Context) = {
val components = new BuiltInComponentsFromContext(context) with Components
components.application
}
}
The main components of the app:
trait Components extends BuiltInComponents with I18nComponents
with RepositoryModule {
lazy val assets: Assets = wire[Assets]
lazy val router: Router = wire[Routes] withPrefix "/"
}
And the repository module:
trait RepositoryModule {
lazy val userRepository = wire[UserRepository]
}
How can I get and use a database connection pool and inject it so it can be used within the repository?