playframework - How does @Inject in Scala work -


i'm wondering how @inject annotation in play-scala works. injects dependency, i'm curious how working. when using on class extending controller , set routes generator injectroutesgenerator seems autmagically create objects classes, how use in other context?

i tried:

@inject val mailer: mailerclient = null 

but doesn't seem work. there posibilities @inject things (that mailerclient, ws ets.) directly value, not controller class?

looks close. change val var because not final , needs injected @ latter stage.

@inject var mailer: mailerclient = null 

i'd check mailerclient library mentioned dependency in project configuration. try wsclient instead it's included default in template:

@inject var ws: wsclient = null 

especially know particular 1 works.

update

created demo on github play-scala template index method changed follows:

import play.api._ import play.api.libs.ws.wsclient import play.api.mvc._ import play.api.libs.concurrent.execution.implicits.defaultcontext  class application extends controller {    @inject var ws: wsclient = null    def index = action.async {     ws.url("http://google.com").get.map(r => ok(r.body))   }  } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -