<div><div>Hi Pete,</div><div><br></div><div>I&#39;m a little concerned with the classloading policy in the CDI class :-)</div><div><br></div><div>The code strongly depends on Thread.currentThread().getContextClassLoader() which isn&#39;t always appropriate, for instance if you try to use it outside of Java EE platform it will not work as expected. Furthermore CDI providers are statically cached once for all, I&#39;m not sure it will nicely work with multiple CDI applications. Maybe we can discuss about enhancing the CDI class to provide another &quot;current()&quot; method with a classloader parameter or a &quot;CDI provider factory&quot; parameter.</div>

<div><br></div><div>Also, as the &quot;current()&quot; method does not take parameters, CDI implementations will need to rely on some static discriminant like TCCL or something like that to find the CDI container of the current application which isn&#39;t always possible. Maybe we can discuss about providing another &quot;current()&quot; (or any other name) method with a discriminant parameter to target the right app.</div>

<div><br></div><div>I&#39;ve just seen Stuart&#39;s pull request. It should work in a Java SE environment, but I&#39;m not sure about modular environment.</div></div><br><div class="gmail_quote">On Wed, Sep 7, 2011 at 12:26 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="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Regarding <a href="https://issues.jboss.org/browse/CDI-14" target="_blank">https://issues.jboss.org/browse/CDI-14</a>, I&#39;ve created this patch <a href="https://github.com/jboss/cdi/pull/43" target="_blank">https://github.com/jboss/cdi/pull/43</a>.<br>


<br>
This also touches on CDI-26, which is about providing an embedded mode (API for starting CDI) - it covers about 50% of that issue. It doesn&#39;t provide a bootstrap API, but it does provide a programmatic API to access the container:<br>


<br>
CDI.current().getBeanManager();<br>
<br>
CDI.current().select(MyBean.class).select(new MyQualifierLiteral()).doSomething();<br>
<br>
(CDI implements Instance)<br>
<br>
I&#39;ve copied the logic for looking up the current CDI instance from the JPA Persistence class.<br>
<br>
Please review, as I know this addresses two much sought after improvement, and I hope that the overall ethos of the approach I&#39;ve taken you guys like. I suspect there are a couple of rough edges to iron out - specifically, I would like feedback on:<br>


<br>
* what happens when multiple CDI providers are located (right now as I straw man I followed JPA&#39;s example and returned the first one loaded, not sure if this right)<br>
* Classloading for the providers (Stuart has a comment here)<br>
_______________________________________________<br>
cdi-dev mailing list<br>
<a href="mailto:cdi-dev@lists.jboss.org">cdi-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
</blockquote></div><br>regards<br><br>Mathieu ANCELIN<br>