[cdi-dev] Extensions and spec-related observer method injection points question

Laird Nelson ljnelson at gmail.com
Fri Feb 17 11:56:04 EST 2017


On Thu, Feb 16, 2017 at 10:08 PM Matej Novotny <manovotn at redhat.com> wrote:

> > Concretely, I'd like to do this:
> >
> > // In my portable extension
> > private static final void doSomethingAtStartup(@Observes
> > @Initialized(ApplicationScoped.class) final Object event, final
> Frobnicator
> > someBean) {
> > someBean.doSomething();
> > }
>
> While you cannot do this, you can still get hold of BeanManager and use it
> to resolve your bean.
>

Right; that's what I'm doing at the moment.


> But I would say this could create quite some confusion if in some observer
> you could inject certain beans and in others you couldn't.
>

Sure.


> Even in your sample, you can only inject AppScoped beans, so imagine you
> do such observer for, say, SessionScoped, what can you inject there?
> SessionScoped for sure, how about Req? Conversation?
>

First, thanks to Martin, Antoine, yourself, etc. for looking at this.  The
issue is not holding me up, and I can make headway, etc.  My remarks here
are just because I'm curious.  :-)

Forgetting about confusion, couldn't I inject any bean I want in a
non-container-lifecycle-event-observing observer method in my extension?  I
understand it's not supported right now, and I also understand Antoine's
excellent point that observing a payload of type Object would, in a
portable extension, be too "broad".  Let's forget about that for a moment,
and pretend that it's not an issue, and just focus on resolution issues.

Surely this:

void MyObserver(@Observes Object payload, SomeBean bean) { ... }

...would work (again, forgetting about the fact that due to resolution
rules this would also be called for lifecycle events; I'm interested purely
in resolution issues of that SomeBean parameter)?

My point is, a portable extension "becomes" a bean (in application scope,
according to the specification), and so therefore is eligible to use other
beans, no matter what scope they're in, some of whose Contexts might be
active, and some of whose might not be active.  Obviously trying to use a
bean before the container has gotten through AfterDeploymentValidation
won't work, but after that point...?

Like I said, now I'm just curious.  :-)

Best,
Laird
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/cdi-dev/attachments/20170217/35dab4fa/attachment.html 


More information about the cdi-dev mailing list