playframework - Use WSClient in scala app (play framework) -
i'm not sure if there's basic i'm missing, can't figure out how use wsclient
. i've seen of examples saying need pass wsclient class dependency, i've done, when run program pass class?
for example, class signature is:
class myclassname(ws: wsclient)
but when instantiate class pass it? i'm happy ignore play! framework stuff if makes easier , use sbt run (which i'm more familiar with).
it's unclear where might using wsclient
, recommended let play framework 'manage' instance of client. when instantiate application, gets injected:
class application @inject() (ws: wsclient) extends controller { ... }
what means inside ...
have access ws
value. can instantiate myclassname
using it:
class application @inject() (ws: wsclient) extends controller { val myclass = myclassname(ws) // passes injected wsclient myclassname }
or can write function returns wsclient
, other area of code can call application
object object handler it.
but key application
object gets handle because of injection, @inject
annotation.
if need generate wsclient
, manage manually, there good instructions here. recommended implementation reliant on play! framework libraries, doesn't depend on application
.
Comments
Post a Comment