0
votes

I'm trying to make some little improvements to play-silhouette-seed sample with the purpose of avoiding manually creation of tables in postgres. I tried to follow the implementation used in

https://github.com/playframework/play-slick/tree/master/samples/computer-database

, but I'm having some issues with injection when I add a bind(classOf[InitialData]).asEagerSingleton() to a InitialData class. I get: Error injecting constructor, java.lang.RuntimeException: There is no started application. I uploaded the tentative app in

https://github.com/renexdev/Play-Auth-Slick-Seed-Load-Schema

. I modified some methods in UserImpl.scala but the important file is the /app/modules/InitialData.scala which is called by the Abstract Module in a bind(classOf[InitialData]).asEagerSingleton() when app starts.
I was suggested to pass an execution context to the initialData class. I tried the def doSomething(implicit ec: ExecutionContext) suggested in

https://github.com/alexandru/scala-best-practices/blob/master/sections/4-concurrency-parallelism.md

and the import play.api.libs.concurrent.Execution.Implicits._ suggested in

Play Framework 2.1 - Cannot find an implicit ExecutionContext

but without success. I would appreciate if anyone could give me some insights on what could be wrong with the injection or with the constructor. Thanks for your time. ReneX

1

1 Answers

1
votes

If you bind a class as eager singleton you must pay attention that your code doesn't reference a static play.api.Play.current call. The Guice bindings are wired before a Play application gets started and the instance you bind as eager singleton will also be instantiated before the application starts. So if you reference a started application in this code you see the error "There is no started application".

The problem in your code is the that the DAOSlick trait creates the DatabaseConfig statically with the help of the static referenced play.api.Play.current. You should inject the DatabaseConfigProvider or the DatabaseConfig instance into your DAO implementations. Please look at the Play Framework documentation how this should be done.