scala - Is there any way to use Inject directly from model or other class without controller? -


i start using playframework 2.5 scala.

the example usage of inject found controller.like:

class sampcontroller @inject()(service:service) extends controller{   def index = action{implict request =>     ..     sample.exec(service)     ..   } }  class sample{   def exec(service:service) = {     ...   } } 

but, i'd injected object directly "sample". there way?

class sampcontroller extends controller{   def index = action{implict request =>     ...     sample.exec()     ...   } }  class sample{   def exec = {      val service:service = #any way injected object here?      ...   } } 

thank you.

you can use guice dependency injection on sample , inject service it, inject sample controller.

@singleton class sampcontroller @inject() (sample: sample) extends controller {   def index = action { implict request =>     ...     sample.exec()     ...   } }  @singleton class sample @inject() (service: service) {    def exec = {     service.dosomething()     ...   } } 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -