Since you covered your problem in the original GitHub repo, I donβt know if this answer is needed, but since you do not fully understand the use of DI frameworks, and I consider it incredibly important to learn this skill, I will try to explain it here and list some advantages.
First, the way you instantiate an instance does not give the DI framework the ability to inject your dependencies. Since new is a language keyword, DI cannot intervene, and the dependencies you need for your class cannot be introduced. How this is done through a constructor or field injection. I will mainly focus on constructor injections because this is the "standard" in the scala world.
If you specify a constructor argument with the @Injected annotation, you are basically talking about a DI structure to resolve this dependency from the container. The DI frame goes and looks for a record of this object inside its container. If it does not exist, it will create it (and resolve its dependencies in the process), and if it is annotated using @Singleton , also save this instance for future use. In most DI infrastructures, you need to specify a start class in most cases, but because you use Play! The framework is not necessary. If you want to use a specific module inside your controller, you can do this:
import javax.inject.Inject import play.api.mvc.Controller class Test @Inject() (val dependency: FooClass) extends Controller { ... }
In this case, FooClass is the name of the class that you want to enter into the controller. Let's say FooClass has a Play Application as a dependency that will be introduced because Play provides a couple of pre-bonded presets like Application , as well as ActorSystem .
This is possible because Play! Framework uses DependencyInjectedRoutes . If you were to create an Actor outside of Control, you will need to specify this inside the module class, but this is explained in this link and this is the link .
There is also the concept of using Traits inside your controller, and then later wiring along with features with implementation classes, but I think now it is too complicated.
If you need some advantages and successful stories for this method of writing applications, here is a good resource: https://softwareengineering.stackexchange.com/a/19204/164366
If you want to read something on this concept:
Hope this clears up! If you have a question, please ask!