2
votes

Before play framework 2.5, i can get current application instance within an object, as following code:

  object MyObj {
      val app = Play.current
  }

But Play.current is deprecated from play 2.5, so how can i get current application instance from MyObj object?

1

1 Answers

2
votes

You need to rewrite MyObj to be a class and then inject the Application:

class MyObj @Inject() (currentApplication: Application) {
    ...
}

Play will then inject the application at your MyObj, which can be injected at other objects as well.

Here are some other discussions with examples and other aspects related to how to use Dependency Injection with Play:

  1. https://stackoverflow.com/a/36685623/4600
  2. https://stackoverflow.com/a/36948125/4600