Skip to content

Instantly share code, notes, and snippets.

@jeffscottbrown
Last active November 16, 2021 14:44
Show Gist options
  • Save jeffscottbrown/ffd90179fbde55b7311323c63f727fd5 to your computer and use it in GitHub Desktop.
Save jeffscottbrown/ffd90179fbde55b7311323c63f727fd5 to your computer and use it in GitHub Desktop.
requestscope (master)$ cat src/main/java/requestscope/Helper.java
package requestscope;
import io.micronaut.runtime.http.scope.RequestScope;
@RequestScope
public class Helper {
public int getTheAnswer() { return 42; }
}
requestscope (master)$
requestscope (master)$ cat src/main/java/requestscope/DemoController.java
package requestscope;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import jakarta.inject.Inject;
@Controller("/demo")
public class DemoController {
@Inject
Helper helper;
@Get(uri = "/", produces = "text/plain")
public String index() {
return "The Answer Is " + helper.getTheAnswer();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment