0

I have a class with the following structure:

package controllers

import play.api.mvc._

class MyController extends Controller {

  private var myVar = ""

  def stepOne() = Action {
    implicit request => {
      myVar = request.queryString("var").mkString
      Ok(views.html.stepOne())
    }
  }


  def stepTwo() = Action {
    implicit request => {
      println(myVar)
      Ok(views.html.stepTwo())
    }
  }
}

The idea is that I can call stepOne with some query parameters, they're saved in the class, then I can retrieve them in stepTwo. This class is only used in testing, to mock out certain functionality.

The problem is myVar is not stored, when I print out myVar in step two, it is still an empty string (I can print it out in step one and it's the correct, non-empty value). What is going on?

mgosk
  • 1,874
  • 14
  • 23
fredley
  • 32,953
  • 42
  • 145
  • 236
  • This question should provide some clarity http://stackoverflow.com/questions/34863486/is-each-play-framework-web-request-handled-with-a-new-dependency-injected-contro – Ryan Stull Jun 09 '16 at 14:44

1 Answers1

2

Just annotate controller as @Singleton.

mgosk
  • 1,874
  • 14
  • 23