开发者

Bean instance of a shorter scope injected in a bean instance of a larger scope in CDI - how does it work?

Consider the following request-scoped CDI bean:

@RequestScoped
public class RequestScopedBean {
    // ...
}

Now, I inject it in a application-scoped bean:

@ApplicationScoped
public class ApplicationScopedBean {
    @Inject private RequestScopedBean requestScopedBean;
    // ...
}

I ran this code and noted that the request-scoped bean in开发者_如何学Cstance is different between two requests but the application-scoped bean instance is the same. My doubt is: how does this work? Is the request-scoped bean instance reattributed to the application-scoped field at each request? Or the proxy of the application-scoped bean just changes between requests?


In CDI each injected object is actually a proxy. So in that case, the proxy probably holds a reference to the RequestContext and on each method invocation gets the correct bean instance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜