[cdi-dev] Dealing with non-passivation-capable dependencies of a normal-scoped bean

Pete Muir pmuir at redhat.com
Tue Mar 6 11:49:16 EST 2012


No, I hadn't thought of that.

Mark, others, any thoughts?

On 5 Mar 2012, at 16:14, Jozef Hartinger wrote:

> 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
> _______________________________________________
> cdi-dev mailing list
> cdi-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/cdi-dev



More information about the cdi-dev mailing list