I would like to know if it's possible to inject dependencies using Guice without having to pass by the routing.
If it is how can I call my class Test @Inject()...
within my application ?
相关问题
- Unusual use of the new keyword
- Get Runtime Type picked by implicit evidence
- What's the point of nonfinal singleton objects
- PlayFramework: how to transform each element of a
- Error in Scala Compiler: java.lang.AssertionError:
相关文章
- Gatling拓展插件开发,check(bodyString.saveAs("key"))怎么实现
- RDF libraries for Scala [closed]
- Why is my Dispatching on Actors scaled down in Akk
- How do you run cucumber with Scala 2.11 and sbt 0.
- how to set H2 primary key id to auto_increment?
- GRPC: make high-throughput client in Java/Scala
- Setting up multiple test folders in a SBT project
- Testing request with CSRF Token in Play framework
I think there are two ways to use Guice in Play framework:
1) Directly instantiate an object based on the binding:
Add Guice to your Build.scala app dependencies
Create a Global class, which extends GlobalSettings, and bind interface to implementation in configure():
In your Controller or any other class, use the @Inject annotation to get an instance of the interface:
2) Dependency Injection for Play Controller
Override GlobalSettings.getControllerInstance to manage controller class instantiation either via Guice:
How to use the Guice injection?
Route definitions starting with @ will be managed by play.GlobalSettings#getControllerInstance method.