How to access Play Framework 2.4 guice Injector in application?

前端 未结 5 1512
予麋鹿
予麋鹿 2021-01-11 21:57

I want to use the getInstance method of the Guice Injector class in Play Framework 2.4, how can I access it?

I have used the Guice Fa

5条回答
  •  难免孤独
    2021-01-11 22:14

    With Play Framework 2.5.x play.api.Play.current is deprecated and DI should always be preferred. Therefore proper way of getting injector instance is by using:

    import play.api.inject.Injector
    import javax.inject.Inject
    
    class SomeClassRequiringInjector @Inject() (injector: Injector) { ... }
    

    Works for me even when doing this with DI Provider class :)

提交回复
热议问题