Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

No, you should not hold a non-transient reference to an instance of a Seam component. In other words, you should not store a component instance in a collection or encapsulate it in such a way that the reference is out of the reach of the Seam container. It is perfectly acceptable to store the reference in a context variable.

Why not? Seam components are designed to be managed by the Seam container. You declare the dependencies of a component Using the @In annotation (or its variants) and Seam takes care of filling these references prior to invoking a component's method, a process known as injection. When the method invocation is complete, Seam then breaks these references using disinjection. Thus, Seam ensures that one component instance never holds a long-term reference to another component instance. If you put the reference out of Seam's reach (by storing it in a collection, for instance), you break the injection/disinjection process.

What if I do? It's certainly not the end of the world if you keep a non-transient reference to a Seam component. However, by doing so, Seam stops intercepting its methods and therefore it ceases to behave as a component. That means bijection won't be applied to it, it cannot use declarative services such as transactions and security, nor can it benefit from any other interceptor-based functionality.

But I want to store components in a collection! Consider storing your references in context variables instead. If you need collection semantics, then after pulling the reference out of the collection, refresh the reference from the Seam container using Component.getInstance().