<p dir="ltr">getInstanceHandler()? +1 for the idea</p>
<div class="gmail_quote">Le 16 mai 2016 11:48, &quot;Martin Kouba&quot; &lt;<a href="mailto:mkouba@redhat.com">mkouba@redhat.com</a>&gt; a écrit :<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Ok, what about something like this (names to be discussed): add a new interface:<br>
<br>
ManagedInstance&lt;T&gt; implements AutoCloseable {<br>
 T get();<br>
}<br>
<br>
and two new methods on Instance:<br>
<br>
ManagedInstance getAndDestroy();<br>
ManagedInstance getAndRelease();<br>
<br>
The first one would return a ManagedInstance whose close() would always call Instance.destroy(). The latter one - close() would only call Instance.destroy() for @Dependent beans.<br>
<br>
Just throwing ideas...<br>
<br>
<br>
Dne 16.5.2016 v 11:23 Romain Manni-Bucau napsal(a):<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I agree with you bit also the default should be smoother. Just trying to<br>
have side by side 2 confusing methods.<br>
<br>
Like the AutoCloseable idea btw.<br>
<br>
Le 16 mai 2016 11:20, &quot;Martin Kouba&quot; &lt;<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a><br>
&lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a>&gt;&gt; a écrit :<br>
<br>
    Dne 16.5.2016 v 11:08 Romain Manni-Bucau napsal(a):<br>
<br>
<br>
        Le 16 mai 2016 10:42, &quot;Martin Kouba&quot; &lt;<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a><br>
        &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a>&gt;<br>
        &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a> &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a>&gt;&gt;&gt; a écrit :<br>
          &gt;<br>
          &gt;<br>
          &gt;<br>
          &gt; Dne 16.5.2016 v 10:36 Romain Manni-Bucau napsal(a):<br>
          &gt;<br>
          &gt;&gt; I see, thks.<br>
          &gt;&gt;<br>
          &gt;&gt; I dont like having 2 methods with the same semantic there<br>
        but agree the<br>
          &gt;&gt; default is misleading for such cases.<br>
          &gt;&gt;<br>
          &gt;&gt; 1. Cant we change the default? looks like current one can<br>
        break apps if<br>
          &gt;&gt; misunderstood and not sure changing it is worse.<br>
          &gt;<br>
          &gt;<br>
          &gt; I think we cannot due to backward compatibility.<br>
          &gt;<br>
          &gt;<br>
          &gt;&gt;<br>
          &gt;&gt; If not<br>
          &gt;&gt;<br>
          &gt;&gt; 2. Maybe we can type the returned type with a release<br>
        method in the<br>
          &gt;&gt; instance  wrapper instead of enriching Instance API making<br>
        it contextual<br>
          &gt;&gt; by nature?:<br>
        w=instance...get();w.getValue().work();w.release(/*no<br>
        param*/);<br>
          &gt;<br>
          &gt;<br>
          &gt; Sorry, I don&#39;t get it. Do you want to change Instance.get()<br>
        signature<br>
        and return some kind of wrapper? A simple snippet might help.<br>
          &gt;<br>
<br>
        Yes get a method to have the wrapper to manage a single instance:<br>
<br>
        @Inject Instance i;<br>
<br>
        ...<br>
<br>
        Wrapper w = i.getSelected();<br>
        ...<br>
        w.getValue().businessmetd();<br>
        ...<br>
        w.release();<br>
<br>
<br>
    Well, we could introduce a new wrapper and even make is<br>
    AutoCloseable, e.g. something like discussed here:<br>
    <a href="http://lists.jboss.org/pipermail/cdi-dev/2016-May/008241.html" rel="noreferrer" target="_blank">http://lists.jboss.org/pipermail/cdi-dev/2016-May/008241.html</a><br>
<br>
    But still you would have to distinguish between destroy() and<br>
    release(). My original proposal was to allow a user to inspect the<br>
    Bean metadata, see also <a href="https://issues.jboss.org/browse/CDI-515" rel="noreferrer" target="_blank">https://issues.jboss.org/browse/CDI-515</a>. But<br>
    guys convinced me ;-)<br>
<br>
<br>
          &gt;&gt;<br>
          &gt;&gt; That is what most framework did finally to integrate with<br>
        CDI so looks<br>
          &gt;&gt; natural.<br>
          &gt;&gt;<br>
          &gt;&gt; Le 16 mai 2016 10:23, &quot;Martin Kouba&quot; &lt;<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a><br>
        &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a>&gt;<br>
        &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a> &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a>&gt;&gt;<br>
          &gt;&gt; &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a> &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a>&gt;<br>
        &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a> &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a>&gt;&gt;&gt;&gt; a écrit :<br>
          &gt;&gt;<br>
          &gt;&gt;     Dne 16.5.2016 v 10:20 Romain Manni-Bucau napsal(a):<br>
          &gt;&gt;<br>
          &gt;&gt;<br>
          &gt;&gt;         Le 16 mai 2016 10:01, &quot;Martin Kouba&quot;<br>
        &lt;<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a> &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a>&gt;<br>
        &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a> &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a>&gt;&gt;<br>
          &gt;&gt;         &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a><br>
        &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a>&gt; &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a><br>
        &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a>&gt;&gt;&gt;<br>
          &gt;&gt;         &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a><br>
        &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a>&gt; &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a><br>
        &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a>&gt;&gt;<br>
        &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a> &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a>&gt;<br>
        &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a> &lt;mailto:<a href="mailto:mkouba@redhat.com" target="_blank">mkouba@redhat.com</a>&gt;&gt;&gt;&gt;&gt; a écrit :<br>
          &gt;&gt;<br>
          &gt;&gt;           &gt;<br>
          &gt;&gt;           &gt; Dne 15.5.2016 v 16:14 John D. Ament napsal(a):<br>
          &gt;&gt;           &gt; &gt; Hey guys<br>
          &gt;&gt;           &gt; &gt;<br>
          &gt;&gt;           &gt; &gt; Seems like we have some issues in JIRA all<br>
        focused on<br>
          &gt;&gt;         managing the<br>
          &gt;&gt;           &gt; &gt; lifecycle of Dependent scoped beans.  It also<br>
        seems like<br>
          &gt;&gt;         we have many<br>
          &gt;&gt;           &gt; &gt; differing opinions about how to manage them.<br>
          &gt;&gt;           &gt; &gt;<br>
          &gt;&gt;           &gt; &gt; - Martin raised a PR to add a release()<br>
        method to Instance<br>
          &gt;&gt;         to help<br>
          &gt;&gt;           &gt; &gt; destroy a dependent bean<br>
          &gt;&gt; <a href="https://github.com/cdi-spec/cdi/pull/286" rel="noreferrer" target="_blank">https://github.com/cdi-spec/cdi/pull/286</a><br>
          &gt;&gt;           &gt; &gt; - I raised a PR<br>
        <a href="https://github.com/cdi-spec/cdi/pull/289" rel="noreferrer" target="_blank">https://github.com/cdi-spec/cdi/pull/289</a><br>
          &gt;&gt;         to update the<br>
          &gt;&gt;           &gt; &gt; spec to clarify how to manage a dependent<br>
        scoped bean.<br>
          &gt;&gt;           &gt; &gt;<br>
          &gt;&gt;           &gt; &gt; Right now, it seems that the big disagreement<br>
        is whether<br>
          &gt;&gt;           &gt; &gt; Instance.destroy() can destroy objects not<br>
        created by it<br>
          &gt;&gt;         (the case<br>
          &gt;&gt;         being<br>
          &gt;&gt;           &gt; &gt; around the CDI utility class, being an impl of<br>
        Instance).  I&#39;m<br>
          &gt;&gt;         currently<br>
          &gt;&gt;           &gt; &gt; heavily against Martin&#39;s proposed changes,<br>
        but want to get<br>
          &gt;&gt;         input from<br>
          &gt;&gt;           &gt; &gt; others on the group to understand their<br>
        perspective.<br>
          &gt;&gt;           &gt; &gt;<br>
          &gt;&gt;           &gt; &gt; - Does the spec require destroy() to be<br>
        called only on<br>
          &gt;&gt;         instances<br>
          &gt;&gt;         that it<br>
          &gt;&gt;           &gt; &gt; created?  When I read 5.6.1 the only<br>
        requirement I see is<br>
          &gt;&gt;         that it<br>
          &gt;&gt;         has to<br>
          &gt;&gt;           &gt; &gt; be a dependent scoped bean.  Note when I ask<br>
        this I&#39;m<br>
          &gt;&gt;         asking from the<br>
          &gt;&gt;           &gt; &gt; spec perspective, its a different problem if<br>
        there&#39;s some<br>
          &gt;&gt;         issues with<br>
          &gt;&gt;           &gt; &gt; implementations following suite (I would<br>
        imagine there<br>
          &gt;&gt;         needs to be some<br>
          &gt;&gt;           &gt; &gt; shared global registry of dependent scoped<br>
        beans for this<br>
          &gt;&gt;         to work).<br>
          &gt;&gt;           &gt; &gt;<br>
          &gt;&gt;           &gt; &gt; - Do we want two methods that effectively do<br>
        the same<br>
          &gt;&gt;         thing?  I don&#39;t<br>
          &gt;&gt;           &gt; &gt; see a strong difference between the two.<br>
          &gt;&gt;           &gt;<br>
          &gt;&gt;           &gt; Instance.destroy() currently always destroys<br>
        the contextual<br>
          &gt;&gt;         instance.<br>
          &gt;&gt;           &gt; Which is not always what users expect. That&#39;s<br>
        why I proposed<br>
          &gt;&gt;         to add<br>
          &gt;&gt;           &gt; Instance.release() -<br>
        <a href="https://github.com/cdi-spec/cdi/pull/286" rel="noreferrer" target="_blank">https://github.com/cdi-spec/cdi/pull/286</a>,<br>
          &gt;&gt;           &gt; previously Instance.getBean() -<br>
          &gt;&gt; <a href="https://github.com/cdi-spec/cdi/pull/273" rel="noreferrer" target="_blank">https://github.com/cdi-spec/cdi/pull/273</a>.<br>
          &gt;&gt;           &gt;<br>
          &gt;&gt;<br>
          &gt;&gt;         Since you give the instance to both I guess the<br>
        intention<br>
        from user<br>
          &gt;&gt;         point of view is obvious and then we dont need 2<br>
        methods. What<br>
          &gt;&gt;         would be<br>
          &gt;&gt;         the other use case?<br>
          &gt;&gt;<br>
          &gt;&gt;<br>
          &gt;&gt; <a href="https://github.com/cdi-spec/cdi/pull/273#issuecomment-179080614" rel="noreferrer" target="_blank">https://github.com/cdi-spec/cdi/pull/273#issuecomment-179080614</a><br>
          &gt;&gt;<br>
          &gt;&gt;<br>
          &gt;&gt;           &gt; &gt;<br>
          &gt;&gt;           &gt; &gt; On the flipside, my change is more a spec<br>
        clarification.<br>
          &gt;&gt;         I&#39;m thinking<br>
          &gt;&gt;           &gt; &gt; more now that it belongs as a reword of 5.6.1<br>
        to clarify<br>
          &gt;&gt;         how to use<br>
          &gt;&gt;           &gt; &gt; destroy() on dependent beans, rather than<br>
        where I put it.<br>
          &gt;&gt;         I think<br>
          &gt;&gt;           &gt; &gt; realistically we have all of the tools needed to<br>
        manage the<br>
          &gt;&gt;         lifecycle of<br>
          &gt;&gt;           &gt; &gt; these classes, just need to clarify them for<br>
        people to<br>
        use.<br>
          &gt;&gt;           &gt; &gt;<br>
          &gt;&gt;           &gt; &gt; John<br>
          &gt;&gt;           &gt; &gt;<br>
          &gt;&gt;           &gt; &gt;<br>
          &gt;&gt;           &gt; &gt; _______________________________________________<br>
          &gt;&gt;           &gt; &gt; cdi-dev mailing list<br>
          &gt;&gt;           &gt; &gt; <a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a><br>
        &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a>&gt;<br>
        &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a><br>
        &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a>&gt;&gt;<br>
        &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a>&gt;<br>
        &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a>&gt;&gt;&gt;<br>
          &gt;&gt;         &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a><br>
        &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a>&gt;<br>
        &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a><br>
        &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a>&gt;&gt;<br>
        &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a>&gt;<br>
        &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a>&gt;&gt;&gt;&gt;<br>
          &gt;&gt;<br>
          &gt;&gt;           &gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
          &gt;&gt;           &gt; &gt;<br>
          &gt;&gt;           &gt; &gt; Note that for all code provided on this list,<br>
        the provider<br>
          &gt;&gt;         licenses<br>
          &gt;&gt;         the code under the Apache License, Version 2<br>
          &gt;&gt;         (<a href="http://www.apache.org/licenses/LICENSE-2.0.html" rel="noreferrer" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>).<br>
        For all other<br>
          &gt;&gt;         ideas<br>
          &gt;&gt;         provided on this list, the provider waives all<br>
        patent and other<br>
          &gt;&gt;         intellectual property rights inherent in such<br>
        information.<br>
          &gt;&gt;           &gt; &gt;<br>
          &gt;&gt;           &gt;<br>
          &gt;&gt;           &gt; --<br>
          &gt;&gt;           &gt; Martin Kouba<br>
          &gt;&gt;           &gt; Software Engineer<br>
          &gt;&gt;           &gt; Red Hat, Czech Republic<br>
          &gt;&gt;           &gt; _______________________________________________<br>
          &gt;&gt;           &gt; cdi-dev mailing list<br>
          &gt;&gt;           &gt; <a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a><br>
        &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a>&gt; &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a><br>
        &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a>&gt;&gt;<br>
        &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a>&gt;<br>
        &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a>&gt;&gt;&gt;<br>
          &gt;&gt;         &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a><br>
        &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a>&gt;<br>
        &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a><br>
        &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a>&gt;&gt;<br>
        &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a>&gt;<br>
        &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a> &lt;mailto:<a href="mailto:cdi-dev@lists.jboss.org" target="_blank">cdi-dev@lists.jboss.org</a>&gt;&gt;&gt;&gt;<br>
          &gt;&gt;<br>
          &gt;&gt;           &gt; <a href="https://lists.jboss.org/mailman/listinfo/cdi-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/cdi-dev</a><br>
          &gt;&gt;           &gt;<br>
          &gt;&gt;           &gt; Note that for all code provided on this list,<br>
        the provider<br>
          &gt;&gt;         licenses<br>
          &gt;&gt;         the code under the Apache License, Version 2<br>
          &gt;&gt;         (<a href="http://www.apache.org/licenses/LICENSE-2.0.html" rel="noreferrer" target="_blank">http://www.apache.org/licenses/LICENSE-2.0.html</a>).<br>
        For all other<br>
          &gt;&gt;         ideas<br>
          &gt;&gt;         provided on this list, the provider waives all<br>
        patent and other<br>
          &gt;&gt;         intellectual property rights inherent in such<br>
        information.<br>
          &gt;&gt;<br>
          &gt;&gt;<br>
          &gt;&gt;     --<br>
          &gt;&gt;     Martin Kouba<br>
          &gt;&gt;     Software Engineer<br>
          &gt;&gt;     Red Hat, Czech Republic<br>
          &gt;&gt;<br>
          &gt;<br>
          &gt; --<br>
          &gt; Martin Kouba<br>
          &gt; Software Engineer<br>
          &gt; Red Hat, Czech Republic<br>
<br>
<br>
    --<br>
    Martin Kouba<br>
    Software Engineer<br>
    Red Hat, Czech Republic<br>
<br>
</blockquote>
<br>
-- <br>
Martin Kouba<br>
Software Engineer<br>
Red Hat, Czech Republic<br>
</blockquote></div>