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

给你一囗甜甜゛ 提交于 2020-03-25 18:01:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!