@RequestScoped
public class RequestScopedClass {
//This class gets constructed once per Servlet request, and is shared among all CDI-managed classes within that request.
@Inject
public RequestScopedClass(SomeDependency someDependency) {
doSomethingWith(someDependency);
}
public RequestScopedClass() {
//Note that it is required that a request scoped class have a public no-args constructor
}
}
If a bean is annotated with @RequestScoped, it will be created once for any request. If two objects depend on a request scoped class, they will both get references to the same object.
Note: Any request scoped bean must have a public no-args constructor. The reason for this will be explained later on.