Skip to content

Instantly share code, notes, and snippets.

@ezhulkov
Last active June 30, 2017 10:27
Show Gist options
  • Save ezhulkov/90d050a0701206d318999f2995f14472 to your computer and use it in GitHub Desktop.
Save ezhulkov/90d050a0701206d318999f2995f14472 to your computer and use it in GitHub Desktop.
@Singleton
class TestController @Inject()(
loggingAction1: LoggingAction1,
loggingAction2: LoggingAction2,
val controllerComponents: ControllerComponents
) extends BaseController {
def StackAction = loggingAction1 andThen loggingAction2
def index = StackAction { rq: Request[_] =>
Ok(s"index page")
}
}
class LoggingAction1 @Inject()(parser: BodyParsers.Default)(implicit ec: ExecutionContext) extends ActionBuilderImpl(parser) {
override def invokeBlock[A](request: Request[A], block: (Request[A]) => Future[Result]) = {
Logger.info("Hello from LoggingAction1")
block(request)
}
}
class LoggingAction2 @Inject()(parser: BodyParsers.Default)(implicit ec: ExecutionContext) extends ActionBuilderImpl(parser) {
override def invokeBlock[A](request: Request[A], block: (Request[A]) => Future[Result]) = {
Logger.info("Hello from LoggingAction2")
block(request)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment