Confixuan
Confixuan

Reputation: 11

Where is the object Action in play.api.mvc?

I am a novice of Play Framework. When I learn it on its webpages. I found some code like this:

import play.api.mvc._
def logging[A](action: Action[A]) = Action.async(action.parser) { request =>
  logger.info("Calling action")
  action(request)
}

I checked its document and there is a function async in ActionBuilder.

How does Action.async works? It seems there is no object Action in play.api.mvc

Upvotes: 0

Views: 314

Answers (1)

Mario Galic
Mario Galic

Reputation: 48430

object Action has been removed in Play 2.8 by Remove deprecated play.api.mvc.Action #9288, and has been replaced by BaseController.Action method which refers to injected controllerComponents.actionBuilder rather than the global objects

  /**
   * ...
   * This is meant to be a replacement for the now-deprecated Action object, and can be used in the same way.
   */
  def Action: ActionBuilder[Request, AnyContent] = controllerComponents.actionBuilder

Notice how, perhaps unconventionally, the method name begins with an uppercase letter. My assumption is this was done to maintain familiar usage

def foo(query: String) = Action {
  Ok
}

Upvotes: 1

Related Questions