问题
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
回答1:
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
}
来源:https://stackoverflow.com/questions/60183866/where-is-the-object-action-in-play-api-mvc