I like what Nik has done so far (in terms of the chain of responsibility pattern for various BM lookups.) So keeping that, let&#39;s talk about what else we need to provide the missing lookup functionality (that we can identify.)<br>
<br>What&#39;s there now is good for a start.<br><br>I agree -- BeanManagerAware is ONLY for places where you absolutely cannot access the beanmanager in a proper fashion, or cannot achieve injection in the proper fashion. This should be very clearly stated -- I&#39;ll update the docs.<br>
<br>--Lincoln<br><br><div class="gmail_quote">On Thu, Apr 15, 2010 at 6:14 AM, Pete Muir <span dir="ltr">&lt;<a href="mailto:pmuir@redhat.com">pmuir@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Guys,<br>
<br>
There still seems to be some confusion about why this is an issue that we *must* address. Taking a step back, we have some general requirements for Seam 3:<br>
<br>
* that we want to use the Java SE platform<br>
* that we also want to use &quot;app servers&quot;<br>
<div class="im">* that we want these extensions to be portable not just across Java EE containers but across Servlet containers too<br>
* that we want this to work in more esoteric deployment scenarios than a single-war-per-server-instance OR bundling the extension as a library of the war OR using special tricks like deployers in JBoss AS<br>
<br>
</div>Then there is *no* general solution to this problem that I know of (I&#39;m not just not telling people what the solution because I&#39;m some sort of sadist ;-). Instead, we have a number of partial solutions, which, when combined should get us the whole way there.<br>

<br>
I see that I was wrong to not put this in Weld Extensions from the beginning. We can take Nik&#39;s basic design, add service providers into the mix (to make this extensible and remove the hard dep on the servlet container) which should at least mean we don&#39;t reinvent a square wheel many times ;-).<br>

<br>
However, it is still *extremely* important that each time you can&#39;t just inject the BeanManager you take a step back, and consider how you need to access the BeanManager. For example, it is infinitely better to push the BeanManager into some sort of locally propagated context than to resort to lookup techniques. There is no guarantee that lookup techniques will work everywhere, whilst a actively propagating the BeanManager will.<br>

<br>
So, before you extend BeanManagerAware, please please consider whether there is a better option. It is a measure of last resort *only*. Often people on the dev list will have a good idea about how to get it, so please ask.<br>

<br>
I will add these notes to the lookup class. Before we do release candidates of a module, you can expect the BeanManagerAware police to visit and possibly demand changes too ;-)<br>
<div><div></div><div class="h5"><br>
On 14 Apr 2010, at 20:53, Nicklas Karlsson wrote:<br>
<br>
&gt; I think the real issue was the singleton extension...<br>
&gt;<br>
&gt; On Wed, Apr 14, 2010 at 10:39 PM, Lincoln Baxter, III &lt;<a href="mailto:lincolnbaxter@gmail.com">lincolnbaxter@gmail.com</a>&gt; wrote:<br>
&gt; The statics are only used instead of new BeanManagerProvider{} ... they are not a problem and can go away. Is there another complaint?<br>
&gt;<br>
&gt;<br>
&gt; On Wed, Apr 14, 2010 at 2:59 PM, Nicklas Karlsson &lt;<a href="mailto:nickarls@gmail.com">nickarls@gmail.com</a>&gt; wrote:<br>
&gt; Reverting &amp; repenting<br>
&gt;<br>
&gt; It&#39;s for the JSF -&gt; CDI event bridge. I need a BeanManager to propagate the events to but the problem is that the first JSF global system event is a PostApplicationConstructed which is pretty soon.<br>
&gt;<br>
&gt; First I try to look for it in a servlet context attribute (which the seam-servlet puts there but it&#39;s not there yet in this case)<br>
&gt; Then I try to look in JNDI (sure, it&#39;s there but you recommended we should try to avoid this to make this available in as many places as possible)<br>
&gt; Then I tried the static one as a last effort.<br>
&gt;<br>
&gt;<br>
&gt; On Wed, Apr 14, 2010 at 5:54 PM, Pete Muir &lt;<a href="mailto:pmuir@redhat.com">pmuir@redhat.com</a>&gt; wrote:<br>
&gt; Guys,<br>
&gt;<br>
&gt; We cannot rely on statics in Seam 3. Please don&#39;t add code like this. If you have a problem accessing the BeanManager from your code, please ask here about the best solution.<br>
&gt;<br>
&gt; Nik, can you revert this please. And then explain what situation you are trying to address.<br>
&gt;<br>
&gt; Thanks.<br>
&gt;<br>
&gt; Begin forwarded message:<br>
&gt;<br>
&gt; &gt; From: <a href="mailto:seam-commits@lists.jboss.org">seam-commits@lists.jboss.org</a><br>
&gt; &gt; Date: 14 April 2010 13:50:21 GMT+01:00<br>
&gt; &gt; To: <a href="mailto:seam-commits@lists.jboss.org">seam-commits@lists.jboss.org</a><br>
&gt; &gt; Subject: [seam-commits] Seam SVN: r12493 - in modules/faces/trunk/impl/src/main: resources/META-INF/services and 1 other directory.<br>
&gt; &gt; Reply-To: <a href="mailto:seam-commits@lists.jboss.org">seam-commits@lists.jboss.org</a><br>
&gt; &gt;<br>
&gt; &gt; Author: nickarls<br>
&gt; &gt; Date: 2010-04-14 08:50:21 -0400 (Wed, 14 Apr 2010)<br>
&gt; &gt; New Revision: 12493<br>
&gt; &gt;<br>
&gt; &gt; Added:<br>
&gt; &gt;   modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerPickupExtension.java<br>
&gt; &gt;   modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/SingletonBeanManagerProvider.java<br>
&gt; &gt; Modified:<br>
&gt; &gt;   modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerAware.java<br>
&gt; &gt;   modules/faces/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension<br>
&gt; &gt; Log:<br>
&gt; &gt; Last attempt singletonish approach when others fail. Yes, I&#39;m ashamed.<br>
&gt; &gt;<br>
&gt; &gt; Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerAware.java<br>
&gt; &gt; ===================================================================<br>
&gt; &gt; --- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerAware.java     2010-04-14 12:21:26 UTC (rev 12492)<br>
&gt; &gt; +++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerAware.java     2010-04-14 12:50:21 UTC (rev 12493)<br>
&gt; &gt; @@ -45,6 +45,7 @@<br>
&gt; &gt;       beanManagerProviders.add(ServletContextBeanManagerProvider.DEFAULT);<br>
&gt; &gt;       beanManagerProviders.add(JndiBeanManagerProvider.DEFAULT);<br>
&gt; &gt;       beanManagerProviders.add(JndiBeanManagerProvider.JBOSS_HACK);<br>
&gt; &gt; +      beanManagerProviders.add(SingletonBeanManagerProvider.DEFAULT);<br>
&gt; &gt;    }<br>
&gt; &gt;<br>
&gt; &gt;    protected BeanManager getBeanManager()<br>
&gt; &gt;<br>
&gt; &gt; Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerPickupExtension.java<br>
&gt; &gt; ===================================================================<br>
&gt; &gt; --- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerPickupExtension.java                           (rev 0)<br>
&gt; &gt; +++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/BeanManagerPickupExtension.java   2010-04-14 12:50:21 UTC (rev 12493)<br>
&gt; &gt; @@ -0,0 +1,56 @@<br>
&gt; &gt; +/*<br>
&gt; &gt; + * JBoss, Home of Professional Open Source<br>
&gt; &gt; + * Copyright 2010, Red Hat, Inc., and individual contributors<br>
&gt; &gt; + * by the @authors tag. See the copyright.txt in the distribution for a<br>
&gt; &gt; + * full listing of individual contributors.<br>
&gt; &gt; + *<br>
&gt; &gt; + * This is free software; you can redistribute it and/or modify it<br>
&gt; &gt; + * under the terms of the GNU Lesser General Public License as<br>
&gt; &gt; + * published by the Free Software Foundation; either version 2.1 of<br>
&gt; &gt; + * the License, or (at your option) any later version.<br>
&gt; &gt; + *<br>
&gt; &gt; + * This software is distributed in the hope that it will be useful,<br>
&gt; &gt; + * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
&gt; &gt; + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br>
&gt; &gt; + * Lesser General Public License for more details.<br>
&gt; &gt; + *<br>
&gt; &gt; + * You should have received a copy of the GNU Lesser General Public<br>
&gt; &gt; + * License along with this software; if not, write to the Free<br>
&gt; &gt; + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA<br>
&gt; &gt; + * 02110-1301 USA, or see the FSF site: <a href="http://www.fsf.org" target="_blank">http://www.fsf.org</a>.<br>
&gt; &gt; + */<br>
&gt; &gt; +package org.jboss.seam.faces.cdi;<br>
&gt; &gt; +<br>
&gt; &gt; +import javax.enterprise.event.Observes;<br>
&gt; &gt; +import javax.enterprise.inject.spi.AfterBeanDiscovery;<br>
&gt; &gt; +import javax.enterprise.inject.spi.BeanManager;<br>
&gt; &gt; +import javax.enterprise.inject.spi.Extension;<br>
&gt; &gt; +<br>
&gt; &gt; +/**<br>
&gt; &gt; + * Singleton(ish) extension that observes the AfterBeanDiscovery event and stores the BeanManager for access<br>
&gt; &gt; + * in places where injection is not available and JNDI or ServletContext access is not preferable.<br>
&gt; &gt; + *<br>
&gt; &gt; + * @author Nicklas Karlsson<br>
&gt; &gt; + *<br>
&gt; &gt; + */<br>
&gt; &gt; +public class BeanManagerPickupExtension implements Extension<br>
&gt; &gt; +{<br>
&gt; &gt; +   private static BeanManagerPickupExtension instance;<br>
&gt; &gt; +   private volatile BeanManager beanManager;<br>
&gt; &gt; +<br>
&gt; &gt; +   public BeanManager getBeanManager()<br>
&gt; &gt; +   {<br>
&gt; &gt; +      return beanManager;<br>
&gt; &gt; +   }<br>
&gt; &gt; +<br>
&gt; &gt; +   public static BeanManagerPickupExtension getInstance()<br>
&gt; &gt; +   {<br>
&gt; &gt; +      return instance;<br>
&gt; &gt; +   }<br>
&gt; &gt; +<br>
&gt; &gt; +   public void pickupBeanManager(@Observes AfterBeanDiscovery e, BeanManager beanManager)<br>
&gt; &gt; +   {<br>
&gt; &gt; +      this.beanManager = beanManager;<br>
&gt; &gt; +      BeanManagerPickupExtension.instance = this;<br>
&gt; &gt; +   }<br>
&gt; &gt; +}<br>
&gt; &gt;<br>
&gt; &gt; Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/SingletonBeanManagerProvider.java<br>
&gt; &gt; ===================================================================<br>
&gt; &gt; --- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/SingletonBeanManagerProvider.java                         (rev 0)<br>
&gt; &gt; +++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/cdi/SingletonBeanManagerProvider.java 2010-04-14 12:50:21 UTC (rev 12493)<br>
&gt; &gt; @@ -0,0 +1,43 @@<br>
&gt; &gt; +/*<br>
&gt; &gt; + * JBoss, Home of Professional Open Source<br>
&gt; &gt; + * Copyright 2010, Red Hat, Inc., and individual contributors<br>
&gt; &gt; + * by the @authors tag. See the copyright.txt in the distribution for a<br>
&gt; &gt; + * full listing of individual contributors.<br>
&gt; &gt; + *<br>
&gt; &gt; + * This is free software; you can redistribute it and/or modify it<br>
&gt; &gt; + * under the terms of the GNU Lesser General Public License as<br>
&gt; &gt; + * published by the Free Software Foundation; either version 2.1 of<br>
&gt; &gt; + * the License, or (at your option) any later version.<br>
&gt; &gt; + *<br>
&gt; &gt; + * This software is distributed in the hope that it will be useful,<br>
&gt; &gt; + * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
&gt; &gt; + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU<br>
&gt; &gt; + * Lesser General Public License for more details.<br>
&gt; &gt; + *<br>
&gt; &gt; + * You should have received a copy of the GNU Lesser General Public<br>
&gt; &gt; + * License along with this software; if not, write to the Free<br>
&gt; &gt; + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA<br>
&gt; &gt; + * 02110-1301 USA, or see the FSF site: <a href="http://www.fsf.org" target="_blank">http://www.fsf.org</a>.<br>
&gt; &gt; + */<br>
&gt; &gt; +package org.jboss.seam.faces.cdi;<br>
&gt; &gt; +<br>
&gt; &gt; +import javax.enterprise.inject.spi.BeanManager;<br>
&gt; &gt; +<br>
&gt; &gt; +/**<br>
&gt; &gt; + * A BeanManager provider for an extension provided singleton<br>
&gt; &gt; + *<br>
&gt; &gt; + * @author Nicklas Karlsson<br>
&gt; &gt; + *<br>
&gt; &gt; + */<br>
&gt; &gt; +public class SingletonBeanManagerProvider implements BeanManagerProvider<br>
&gt; &gt; +{<br>
&gt; &gt; +<br>
&gt; &gt; +   public static final BeanManagerProvider DEFAULT = new SingletonBeanManagerProvider();<br>
&gt; &gt; +<br>
&gt; &gt; +   @Override<br>
&gt; &gt; +   public BeanManager getBeanManager()<br>
&gt; &gt; +   {<br>
&gt; &gt; +      return BeanManagerPickupExtension.getInstance().getBeanManager();<br>
&gt; &gt; +   }<br>
&gt; &gt; +<br>
&gt; &gt; +}<br>
&gt; &gt;<br>
&gt; &gt; Modified: modules/faces/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension<br>
&gt; &gt; ===================================================================<br>
&gt; &gt; --- modules/faces/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension       2010-04-14 12:21:26 UTC (rev 12492)<br>
&gt; &gt; +++ modules/faces/trunk/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension       2010-04-14 12:50:21 UTC (rev 12493)<br>
&gt; &gt; @@ -1,3 +1,4 @@<br>
&gt; &gt; org.jboss.seam.faces.context.ViewScopedExtension<br>
&gt; &gt; org.jboss.seam.faces.context.FlashScopedExtension<br>
&gt; &gt; -org.jboss.seam.faces.context.FacesAnnotationsAdapterExtension<br>
&gt; &gt; \ No newline at end of file<br>
&gt; &gt; +org.jboss.seam.faces.context.FacesAnnotationsAdapterExtension<br>
&gt; &gt; +org.jboss.seam.faces.cdi.BeanManagerPickupExtension<br>
&gt; &gt;<br>
&gt; &gt; _______________________________________________<br>
&gt; &gt; seam-commits mailing list<br>
&gt; &gt; <a href="mailto:seam-commits@lists.jboss.org">seam-commits@lists.jboss.org</a><br>
&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/seam-commits" target="_blank">https://lists.jboss.org/mailman/listinfo/seam-commits</a><br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; seam-dev mailing list<br>
&gt; <a href="mailto:seam-dev@lists.jboss.org">seam-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/seam-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/seam-dev</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; ---<br>
&gt; Nik<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; seam-dev mailing list<br>
&gt; <a href="mailto:seam-dev@lists.jboss.org">seam-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/seam-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/seam-dev</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Lincoln Baxter, III<br>
&gt; <a href="http://ocpsoft.com" target="_blank">http://ocpsoft.com</a><br>
&gt; <a href="http://scrumshark.com" target="_blank">http://scrumshark.com</a><br>
&gt; &quot;Keep it Simple&quot;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; ---<br>
&gt; Nik<br>
<br>
<br>
_______________________________________________<br>
seam-dev mailing list<br>
<a href="mailto:seam-dev@lists.jboss.org">seam-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/seam-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/seam-dev</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Lincoln Baxter, III<br><a href="http://ocpsoft.com">http://ocpsoft.com</a><br><a href="http://scrumshark.com">http://scrumshark.com</a><br>&quot;Keep it Simple&quot;<br>