[cdi-dev] [JBoss JIRA] (CDI-457) Add a disposable interface

John Ament (JIRA) issues at jboss.org
Sun Sep 7 08:43:00 EDT 2014


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

John Ament commented on CDI-457:
--------------------------------

{code}Instance.destroy(){code} is probably the closest to what I'm looking for, but less error prone.  There were a few ways I was thinking to solve this, first is

{code}
@Produces
@UnManaged
public SomeClass produceSomeClass() {...
{code}

@UnManaged would be a new annotation indicating that the returned object is not contextual (and hence, implicitly dependent).  Another way, using the Instance<> approach would be:

{code}
Disposable<SomeClass> dsc = CDI.current().select(SomeClass.class).getDisposable();
try(SomeClass sc = dsc.get()) {
    // do something with some class
}
{code}

so that when the Disposable object goes out of scope, it gets cleaned up.

> Add a disposable interface
> --------------------------
>
>                 Key: CDI-457
>                 URL: https://issues.jboss.org/browse/CDI-457
>             Project: CDI Specification Issues
>          Issue Type: Feature Request
>          Components: Contexts
>            Reporter: John Ament
>            Assignee: John Ament
>
> Currently for Dependent scoped beans, there's no way for the container to be aware when it's no longer needed.
> I suggest that we somehow wrap dependent beans in a Disposable wrapper to be notified when it's not needed any longer.



--
This message was sent by Atlassian JIRA
(v6.3.1#6329)


More information about the cdi-dev mailing list