<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&#39;s the case, but rather special beans since you can&#39;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 &lt;<a href="mailto:ljnelson@gmail.com">ljnelson@gmail.com</a>&gt; 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 &lt;<a href="mailto:manovotn@redhat.com" class="gmail_msg" target="_blank">manovotn@redhat.com</a>&gt; 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">&gt; Concretely, I&#39;d like to do this:<br class="gmail_msg">
&gt;<br class="gmail_msg">
&gt; // In my portable extension<br class="gmail_msg">
&gt; private static final void doSomethingAtStartup(@Observes<br class="gmail_msg">
&gt; @Initialized(ApplicationScoped.class) final Object event, final Frobnicator<br class="gmail_msg">
&gt; someBean) {<br class="gmail_msg">
&gt; someBean.doSomething();<br class="gmail_msg">
&gt; }<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&#39;s what I&#39;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&#39;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&#39;m curious.  :-)</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Forgetting about confusion, couldn&#39;t I inject any bean I want in a non-container-lifecycle-event-observing observer method in my extension?  I understand it&#39;s not supported right now, and I also understand Antoine&#39;s excellent point that observing a payload of type Object would, in a portable extension, be too &quot;broad&quot;.  Let&#39;s forget about that for a moment, and pretend that it&#39;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&#39;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 &quot;becomes&quot; a bean (in application scope, according to the specification), and so therefore is eligible to use other beans, no matter what scope they&#39;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&#39;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&#39;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>