[cdi-dev] [JBoss JIRA] (CDI-45) Optional Injection Points

John Ament (JIRA) issues at jboss.org
Tue Oct 11 18:38:00 EDT 2016


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

John Ament commented on CDI-45:
-------------------------------

Underestood.  The way I see it, for each Bean of type {{<T>}} there exists a Bean of type {{Optional<T>}} that shares the same qualifiers but has scope dependent.  Optional beans can't be looked up programmatically.

Another way to do this is to add all methods from https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html to Instance, which would be:

* ifPresent
* isPresent
* orElse
* orElseGet
* orElseThrow

So hm.

> Optional Injection Points
> -------------------------
>
>                 Key: CDI-45
>                 URL: https://issues.jboss.org/browse/CDI-45
>             Project: CDI Specification Issues
>          Issue Type: Feature Request
>          Components: Resolution
>    Affects Versions: 1.0
>            Reporter: Stuart Douglas
>            Priority: Optional
>             Fix For: TBD
>
>
> There are occoasions where it may be useful for some injection points to be optional, e.g.
> @Inject
> @Optional 
> MyBean bean; 
> This would behave the same as a normal injection point, however it will not cause the deployment to fail if it is not satisified. 



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


More information about the cdi-dev mailing list