Hi;

Actually the spec requires to return Proxy objects from the Manager.getInstance(). So the dependency injection does not occur until Bean method is called, i.o.w Context.get() is not called before the any method calls on the Bean.

So, circular reference may not be happened with Proxy usage.

Gurkan


From: Gavin King <gavin@hibernate.org>
To: Scott Ferguson <ferg@caucho.com>
Cc: Michael Keith <michael.keith@oracle.com>; WebBeans <webbeans-dev@lists.jboss.org>; Java Community Process JSR #299 Expert List <JSR-299-EG@jcp.org>
Sent: Friday, January 2, 2009 6:29:46 AM
Subject: Re: [webbeans-dev] Re: Bean.getInjectionPoints()

On Fri, Jan 2, 2009 at 2:37 PM, Scott Ferguson <ferg@caucho.com> wrote:
>
> On Dec 30, 2008, at 1:35 PM, Gavin King wrote:
>
>> The spec requires that injection points be validated at init time for
>> any Bean (for XxxxxDependencyException).
>>
>> Nick from the RI team has noticed that for this to be implementable,
>> we need to add metadata about the injection points of a bean to the
>> Bean interface.
>
> It shouldn't be necessary, since "SimpleBean implements Bean" should be
> responsible for its own validation.  It doesn't make sense for the Manager
> implementation to validate the Bean, since that breaks the encapsulation
> model of both Manager and Bean.  It's cleaner for Manager to assume the Bean
> is valid.

That only works for Bean implementations provided in the
specification. It does not work for Bean implementations provided by
3rd-party extensions. We need the dependency validation stuff to work
in the second case also.

> On a related note, it would be cleaner if the Bean.create() method was
> changed to Bean.create(Context) in order to handle circular references.
>
> The logic of Bean.create(Context) would be
>  1. check if Bean is in Context (for circular ref), if so return the bean.
>  2. instantiate the Bean (do not inject/initialize) and put it in Context
> (so we have a ref)
>  3. inject/initialize the bean as usual (this may trigger the circular
> reference, which would be resolved by #1 on a second call).

Bean already has a reference to the Manager and can call
Manager.getContext(myScope). So the extra parameter would not be
necessary.

But what you're really saying is that it's better to handle circular
references from Bean.create() than from Manager.getInstance(). OK,
that's really interesting, let me chat to Pete Muir about that and get
back to you.

--
Gavin King
gavin.king@gmail.com
http://in.relation.to/Bloggers/Gavin
http://hibernate.org
http://seamframework.org
_______________________________________________
webbeans-dev mailing list
webbeans-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/webbeans-dev