Skip to content

Instantly share code, notes, and snippets.

@mchv
Last active June 30, 2017 16:56
Show Gist options
  • Save mchv/aebe1ce3b138dfdaf006c239b1f942a1 to your computer and use it in GitHub Desktop.
Save mchv/aebe1ce3b138dfdaf006c239b1f942a1 to your computer and use it in GitHub Desktop.
Old style playframework controller to reduce boilerplate
package play.api.mvc.legacy
import play.api.mvc._
class Controller extends BaseController {
override protected def controllerComponents: ControllerComponents = {
Controller.components /* we don't null check here to avoid the cost associated to it - we expect devs to have done the init properly */
}
}
object Controller {
private var components: ControllerComponents = null
/*
This need to be called when you initialise the app in app compoments
*/
def init(c: ControllerComponents) = {
components = c
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment