I am trying to figure out how to use dependency injection in Play Framework 2.4. I am familiar with the general principles, but I donβt really understand the implications for the design. My general reasoning was that the static methods in the controller classes are too similar to global variables, and this can easily cause thread safety problems, etc., and also contribute to poor design overall. Since Play now encourages the switch to dependency injection, I also have to switch.
What I am confused about is that it is good practice in this context. When I read the official Play docs, he briefly talks about dependency injection, and then quickly mentions the @Singleton annotation. And an accessible example ( http://www.typesafe.com/activator/template/play-guice ) talks about the same word, "WelcomeTextGenerator".
So I'm wondering if singleton objects should be used, as the examples show? If so, what is the advantage over older static methods? Are there specific types of objects (for example, controllers?) That need to be single-point, and are there any performance implications for not marking objects as single points?
myrosia
source share