[cdi-dev] Dealing with non-passivation-capable dependencies of a normal-scoped bean
Jozef Hartinger
jharting at redhat.com
Mon Mar 5 11:14:41 EST 2012
Hello,
with https://github.com/jboss/cdi/pull/47 in place the validation rules
for dependencies of normal-scoped components have been weakened. The
idea is that CDI should not enforce dependencies to be passivation
capable if these dependencies are only used temporarily in the
initialization of a normal-scoped bean. Consider the following example:
@SessionScoped
public class Foo implements Serializable {
@Inject
public Foo(Bar bar) {
}
}
public class Bar {
}
CDI now considers this scenario to be valid. However, the Bar instance
is still technically a dependent instance of Foo and the container still
needs to retain a reference to it in order to destroy it properly. The
problem arises when the session is serialized. Although the Foo instance
does not reference the Bar instance and can therefore be serialized, the
CreationalContext of Foo still holds the dependent instance and is
therefore not serializable.
I came up with an idea of how to implement it in Weld at
https://issues.jboss.org/browse/WELD-1076 . However, I do not consider
this approach to be very clean and intuitive for specification
implementors. Therefore, I want to make sure that the specification is
really intended to be implemented this way and that this is not an
oversight in the specification.
JH
More information about the cdi-dev
mailing list