Play Framework PathBindable with dependency injection

I am porting the Scala Play application to 2.5 and am currently porting my components to dependency injection. There is one place left where I do not understand how to do this. I have an implicit PathBindable transformation defined in a companion object:

object Task { implicit def pathBindable(implicit stringBinder: PathBindable[String]) = new PathBindable[Task] { ... } } 

The PathBindable implementation should look for the object from the repository, but I did not find a way for the dependencies to embed the repository here. As a workaround, I use the now obsolete Play object:

 val tasks = Play.application(Play.current).injector.instanceOf[TasksRepository] 

Any ideas how to solve this?

+7
scala dependency-injection playframework
source share
2 answers

According to Lightbend engineer Greg Metwin , PathBindables should only depend on the state in transit. The reason is that the code works in the input / output stream and therefore should be fast and not block.

+3
source share

I think this is the only way to access such things in objects.

It is best to create such a transformer:

 class TaskPathBinder @Inject() ( tasks : TaskRepository ) extends PathBindable[Task]{ // implementiation } 

and then enter it in such services

 class NeedsTaskPathBinder @Inject() ( service : SomeSerive ) (implicit taskPathBinder : TaskPathBinder) { ... } 

Hope you have an idea.

0
source share

All Articles