Documentation

You are viewing the documentation for the 2.5.0 release in the 2.5.x series of releases. The latest stable release series is 3.0.x.

§Removing GlobalSettings

If you are keen to use dependency injection, we are recommending that you move out of your GlobalSettings implementation class as much code as possible. Ideally, you should be able to refactor your code so that it is possible to eliminate your GlobalSettings class altogether.

Next follows a method-by-method guide for refactoring your code. Because the APIs are slightly different for Java and Scala, make sure to jump to the appropriate subsection.

Note: If you haven’t yet read about dependency injection in Play, make a point to do it now. Follow the appropriate link to learn about dependency injection in Play with Java or Scala.

§Scala

if(statusCode == play.api.http.Status.NOT_FOUND) {
  // move your implementation of `GlobalSettings.onHandlerNotFound` here
}
if(statusCode == play.api.http.Status.BAD_REQUEST) {
  // move your implementation of `GlobalSettings.onBadRequest` here
}

Also, mind that if your Global class is mixing the WithFilters trait, you should now create a Filter class that inherits from HttpFilters, and place it in the empty package. Read here for more details.

§Java

if(statusCode == play.mvc.Http.Status.NOT_FOUND) {
  // move your implementation of `GlobalSettings.onHandlerNotFound` here
}
if(statusCode == play.mvc.Http.Status.BAD_REQUEST) {
  // move your implementation of `GlobalSettings.onBadRequest` here
}

Next: Migrating Anorm