<div dir="ltr">Check <a href="https://issues.jboss.org/browse/WELD-2338">https://issues.jboss.org/browse/WELD-2338</a><div><br></div><div>Regarding Extension being beans, it's the case, but rather special beans since you can't perform field, constructor or initializer injection in them.</div><div>For observer that might be called during bootstrap (observing Object for instance) they will throw exception if they inject parameters as well since their matching beans are not resolvable yet.</div><div>A good practice could be: use observers with personal payload without parameter injection and only for specific operation during bootstrap (Romain wrote an interesting post on the topic: <a href="https://blog-rmannibucau.rhcloud.com/#/post/share-data-in-cdi-extensions">https://blog-rmannibucau.rhcloud.com/#/post/share-data-in-cdi-extensions</a>)</div><div>Create a specific bean to declare your observers and inject the extension and other beans as parameter.</div><div><br></div><div>If you really want to have your observers in your extension, inject BeanManager and perform the resolution with it...</div><div><br></div><div>Antoine </div><div><br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Feb 17, 2017 at 5:56 PM Laird Nelson <<a href="mailto:ljnelson@gmail.com">ljnelson@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Thu, Feb 16, 2017 at 10:08 PM Matej Novotny <<a href="mailto:manovotn@redhat.com" class="gmail_msg" target="_blank">manovotn@redhat.com</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">> Concretely, I'd like to do this:<br class="gmail_msg">
><br class="gmail_msg">
> // In my portable extension<br class="gmail_msg">
> private static final void doSomethingAtStartup(@Observes<br class="gmail_msg">
> @Initialized(ApplicationScoped.class) final Object event, final Frobnicator<br class="gmail_msg">
> someBean) {<br class="gmail_msg">
> someBean.doSomething();<br class="gmail_msg">
> }<br class="gmail_msg">
<br class="gmail_msg">
While you cannot do this, you can still get hold of BeanManager and use it to resolve your bean.<br class="gmail_msg"></blockquote><div class="gmail_msg"><br class="gmail_msg"></div></div></div><div dir="ltr" class="gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg">Right; that's what I'm doing at the moment.</div></div></div><div dir="ltr" class="gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg"> </div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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.<br class="gmail_msg"></blockquote><div class="gmail_msg"><br class="gmail_msg"></div></div></div><div dir="ltr" class="gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg">Sure.</div></div></div><div dir="ltr" class="gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg"> </div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Even in your sample, you can only inject AppScoped beans, so imagine you do such observer for, say, SessionScoped, what can you inject there?<br class="gmail_msg">
SessionScoped for sure, how about Req? Conversation?<br class="gmail_msg"></blockquote><div class="gmail_msg"><br class="gmail_msg"></div></div></div><div dir="ltr" class="gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg">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. :-)</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">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.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Surely this:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><span style="color:rgb(33,33,33);font-size:13px" class="gmail_msg">void MyObserver(@Observes Object payload, SomeBean bean) { ... }</span></div><div class="gmail_msg"><span style="color:rgb(33,33,33);font-size:13px" class="gmail_msg"><br class="gmail_msg"></span></div><div class="gmail_msg"><span style="color:rgb(33,33,33);font-size:13px" class="gmail_msg">...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)? </span></div><div class="gmail_msg"><span style="color:rgb(33,33,33);font-size:13px" class="gmail_msg"><br class="gmail_msg"></span></div><div class="gmail_msg"><span style="color:rgb(33,33,33);font-size:13px" class="gmail_msg">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...?</span></div><div class="gmail_msg"><span style="color:rgb(33,33,33);font-size:13px" class="gmail_msg"><br class="gmail_msg"></span></div><div class="gmail_msg"><font color="#212121" class="gmail_msg">Like I said, now I'm just curious. :-)</font></div><div class="gmail_msg"><font color="#212121" class="gmail_msg"><br class="gmail_msg"></font></div><div class="gmail_msg"><font color="#212121" class="gmail_msg">Best,</font></div><div class="gmail_msg"><font color="#212121" class="gmail_msg">Laird</font></div></div></div>
_______________________________________________<br class="gmail_msg">
cdi-dev mailing list<br class="gmail_msg">
<a href="mailto:cdi-dev@lists.jboss.org" class="gmail_msg" target="_blank">cdi-dev@lists.jboss.org</a><br class="gmail_msg">
<a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br class="gmail_msg">
<br class="gmail_msg">
Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (<a href="http://www.apache.org/licenses/LICENSE-2.0.html" rel="noreferrer" class="gmail_msg" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.</blockquote></div>