On Fri, Jan 2, 2009 at 2:37 PM, Scott Ferguson <ferg(a)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(a)gmail.com
http://in.relation.to/Bloggers/Gavin
http://hibernate.org
http://seamframework.org