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

Christian Fechner commented on WELD-975:
----------------------------------------

I investigated this issue a little bit and found following:

This is an example, that is currently not working:
{noformat}
...
@SessionScoped
public class SomeBean {

@Inject @New
Instance<SomeBean2> someBean2Provider;
}
...
{noformat}

However, this is working:
{noformat}
...
@SessionScoped
public class SomeBean {

@Inject @New
SomeBean2 someBean2;

@Inject @New
Instance<SomeBean2> someBean2Provider;
}
...
{noformat}

It seems that in the second case WELD is satisfied, cause it could resolve the 
dependency due to the additional "normal" injection.

While this may be a workaround for many cases, it does not work for the 
following example, where a bean wants to inject an instance of itself:
{noformat}
...
@SessionScoped
public class SomeBean {

@Inject @New
Instance<SomeBean> someBeanProvider;
}
...
{noformat}

Applying the workaround here would correctly result in an error due to a 
circular dependency. But the example itself is valid, cause the 
someBeanProvider can be used to inject 0-n instances of the bean, so that the 
recursion can be avoided programatically.
Such construction occurs for example, when a tree of beans should be 
constructed dynamically depending on database content, which also represents a 
tree structure.

So when fixing the resolving for the "@Inject @New Instance<SomeBean>" case, it 
must be ensured, that the validation does not complain about a circular 
dependency.
                
> Programmatic lookup with @New qualifier not working
> ---------------------------------------------------
>
>                 Key: WELD-975
>                 URL: https://issues.jboss.org/browse/WELD-975
>             Project: Weld
>          Issue Type: Bug
>    Affects Versions: 1.1.2.Final
>         Environment: JBoss AS7
> TestNG
> Arquillian CR5
>            Reporter: Martin Kouba
>
> According to spec: "...the @New qualifier may be used, allowing the 
> application to obtain a @New qualified bean, as defined in Section 3.12, @New 
> qualified beans" (CDI 1.0; chapter 5.6. Programmatic lookup).
> However using programmatic lookup with @New qualifier like:
> {code}
> @Inject @New Instance<Foo> foo;
> {code}
> results in:
> {code}
> org.jboss.weld.exceptions.UnsatisfiedResolutionException: WELD-001308 Unable 
> to resolve any beans for Types: [class 
> org.jboss.cditck.arquillian.instance.Foo]; Bindings: 
> [@javax.enterprise.inject.New(value=org.jboss.cditck.arquillian.instance.Foo.class)]
> {code}
> after trying to obtain reference via get() method.
> Following code works ok:
> {code}
> @Inject @New Foo foo;
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        
_______________________________________________
weld-issues mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/weld-issues

Reply via email to