package controllers;
import javax.inject.*;
import play.*;
import play.mvc.*;
import services.Counter;
/**
* This controller demonstrates how to use dependency injection to
* bind a component into a controller class. The class contains an
* action that shows an incrementing count to users. The {@link Counter}
* object is injected by the Guice dependency injection system.
*/
@Singleton
public class CountController extends Controller {
private final Counter counter;
@Inject
public CountController(Counter counter) {
this.counter = counter;
}
/**
* An action that responds with the {@link Counter}'s current
* count. The result is plain text. This action is mapped to
* GET
requests with a path of /count
* requests by an entry in the routes
config file.
*/
public Result count() {
return ok(Integer.toString(counter.nextCount()));
}
}