Scala (Play 2.4.x) How to call a class with @inject() annotation

前端 未结 4 1911
臣服心动
臣服心动 2021-02-06 05:29

I\'m looking at the scaly code example from play-mailer: https://github.com/playframework/play-mailer

It goes basically like this:

class MyComponent @         


        
4条回答
  •  情话喂你
    2021-02-06 05:48

    this is not a scala Issues, but a DI one. You should read some guice documentation.

    In Play 2.4.x, you need to use dependency injection (https://www.playframework.com/documentation/2.4.x/ScalaDependencyInjection) to achieve your goal.

    Your AnObject should be:

    @Singleton class AnObject @Inject()(mailer:MyComponent){
     def sendEmail = mailer.doStuff
    }
    

提交回复
热议问题