Tutorial by Examples

public class DependentScopedClass { //This class has no scoping annotations, so a new instance gets created at every injection point. @Inject public DependentScopedClass(SomeDependency someDependency) { doSomethingWith(someDependency); } } The default scope for...
@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); ...
@ApplicationScoped public class ApplicationScopedClass { //This class gets constructed once for the entire life of the application, and is shared among all CDI-managed classes throughout the life of the application. @Inject public ApplicationScopedClass(SomeDependency someDependenc...
@SessionScoped public class SessionScopedClass implements Serializable { //This class gets constructed once per session, and is shared among all CDI-managed classes within that session. Notice that it implements Serializable, since the instance will get put on the session. @Inject ...

Page 1 of 1