[cdi-dev] [JBoss JIRA] (CDI-519) Instance.destroy() cannot be used for dependent bean instances not created by the same Instance object

Martin Kouba (JIRA) issues at jboss.org
Tue Sep 8 03:49:00 EDT 2015


    [ https://issues.jboss.org/browse/CDI-519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13106167#comment-13106167 ] 

Martin Kouba commented on CDI-519:
----------------------------------

bq. 2. to explicitly state that Instance<T> can be used to destroy any dependent scoped bean instance of T.
I'm not sure this is doable. A dependent bean instance doesn't know the object it depends on. That's what {{CreationalContext}} is for.
bq. In your example if we go for 1, there will be no solution to destroy the instance you requested thru CDI.
Well, it is. But it's not so easy to implement and also not 100% reliable (see WELD-1917 for more info how this is solved in Weld 2.2.11+). Moreover, it's not clear in the spec - e.g. the {{CDI.current()}} contract does not state anything about the identity of the CDI instance you get and whether it should be possible to use it to destroy any bean instance.

> Instance.destroy() cannot be used for dependent bean instances not created by the same Instance object
> ------------------------------------------------------------------------------------------------------
>
>                 Key: CDI-519
>                 URL: https://issues.jboss.org/browse/CDI-519
>             Project: CDI Specification Issues
>          Issue Type: Clarification
>    Affects Versions: 1.2.Final
>            Reporter: Martin Kouba
>             Fix For: 2.0 (discussion)
>
>
> 5.6.1. The Instance interface:
> {quote}
> The method destroy() instructs the container to destroy the instance. The bean instance passed to destroy() should be *a dependent scoped bean instance*, or...
> {quote}
> I think this should be more obvious. E.g. this wouldn't work correctly even though it doesn't violate the spec:
> {code:java}
> @Dependent
> class Bar {
> }
> class Foo {
>   @Inject
>   Instance<Bar> instance;
>   void ping() {
>     instance.destroy(CDI.current().select(Bar.class).get());
>   }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.11#64026)


More information about the cdi-dev mailing list