Scopes Contexts - mareknovotny/seam-migration GitHub Wiki
Seam 2 provides a fixed set of contexts. These are listed in the table
below. Any java type can be stored in a context. Session and
conversation contexts require the values to be serializable. In Seam 2,
the scope of a component is defined using one of the values of the
ScopeType enumeration, e.g. @Scope(ScopeType.SESSION).
CDI provides a similar set of contexts. This set can be extended by
additional scopes provided by portable extensions that implement the
required SPI. In CDI, each scope has an associated annotation, the name of which
consists of the scope name suffixed by "Scoped", e.g. @SessionScoped.
CDI scopes are split into two groups:
-
Normal scopes — Implemented using dynamic proxies — the client receives a dynamic proxy for the contextual object. Every time a method is invoked on a proxy, the container guarantees that the method is invoked on the actual contextual instance. Most of the built-in CDI scopes are normal scopes.
-
Pseudo-scopes — Client proxies are not required for pseudo-scopes. CDI provides single built-in pseudo-scope —
@Dependent
As a result of using dynamic proxies for implementing normal scopes
(every scope except for @Dependent), every managed bean bound to a
normal scope is required to be proxyable. The exact definition of a
proxyable bean is defined in the
specification.
This may be a problem for legacy applications that use unproxyable beans
(e.g. an instance of java.lang.String bound to the session scope). Possible solutions include:
-
making the bean proxyable (e.g. adding a non-private no-arg constructor or removing the final modifier of a class or method)
-
creating a holder object that wraps the unproxyable object but is itself proxyable
-
using
@Dependentscope instead of a normal scope if possible
Corresponding scopes:
| Seam 2 Scope | CDI Scope |
|---|---|
Event |
Request |
Session |
Session |
Stateless |
No exact match. The stateless scope is used
primarily for Stateless Session Beans (EJB) in Seam 2. A Stateless
session bean can be bound to the |
No exact match |
Dependent — new instance for each injection point. |
Page |
No exact match. |
Conversation |
No exact match. There are several alternatives which help to maintain conversational state: |