[cdi-dev] [JBoss JIRA] (CDI-616) Injection point declared as transient is not useful

Mark Struberg (JIRA) issues at jboss.org
Fri Jun 10 06:30:00 EDT 2016


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

Mark Struberg commented on CDI-616:
-----------------------------------

There are cases where it make sense. But actually only with method and ct injection points.

In the first case we obviously need to store the info about the dependent bean in the enclosing CreationalContext
{code}
public class MySample {
  private MyBean mb;

  @Inject
  public setMe(MyBean mb) {
    this.mb = mb;
  }
}
{code}

In the second example it makes perfect sense to mark the injection point as transient:
{code}
public class MySample {
  private OtherStuff os;

  @Inject
  public setMe(@TransientReference MyBean mb) {
    this.os = mb.createOtherStuff();
  }
}
{code}

> Injection point declared as transient is not useful
> ---------------------------------------------------
>
>                 Key: CDI-616
>                 URL: https://issues.jboss.org/browse/CDI-616
>             Project: CDI Specification Issues
>          Issue Type: Clarification
>          Components: Concepts
>    Affects Versions: 1.2.Final
>         Environment: n/a
>            Reporter: Emily Jiang
>            Priority: Minor
>
> An injection point declared as 'transient' is not useful, due to the fact of after bean's passivation, the transient field will not be reinjected and its value will be lost. This causes confusion. See Weld forum discussion [link title|https://developer.jboss.org/thread/179486]. In the section 5.5.7, how about to make the following changes?
> The isTransient() method returns true if the injection point is a transient field, and
> false otherwise. If the injection point represents a dynamically obtained instance then the
> isTransient() method returns true if the Instance injection point is a transient field, and
> false otherwise.
> =>
> The isTransient() method returns true if the injection point is a transient field, and
> false otherwise. If the injection point represents a dynamically obtained instance then the
> isTransient() method returns true if the Instance injection point is a transient field, and
> false otherwise. If this injection point is declared as transient, after bean's passivation, the value will not be restored. Instance injection point is the preferred approach.
> Any other better suggestions?



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


More information about the cdi-dev mailing list