官术网_书友最值得收藏!

Dependent pseudo-scope

This is the default scope of a CDI bean (@Named) when nothing is specified. In this case, an object exists to serve exactly one bean and has the same life cycle as that bean; an instance of a dependent scoped bean is not shared between different users or different points of injection. It can also be explicitly specified by annotating the bean with the @Dependent annotation and importing javax.enterprise.context.Dependent. This scope is available only in CDI and is the only non-contextual scope.

Note

All CDI scopes, except this one, are known as normal scopes. More details about normal scopes versus pseudo-scopes can be found in the Normal scopes and pseudo-scopes section at http://docs.jboss.org/cdi/spec/1.0/html/contexts.html.

If you put the PlayersBean in the dependent scope, then the current extracted player and the list of randomly extracted players (which will be empty or will contain this player) is available only inside the bean, as shown in the following code:

import javax.enterprise.context.Dependent;
import javax.inject.Named;

@Named
@Dependent
public class PlayersBean {
  ...
}

Note

A method annotated with @PostConstruct will be called for each request. Actually, it might be called multiple times during the same request, if the bean is used in several EL expressions. Initially, there is one instance of the bean, and this instance is reused if the bean EL name appears multiple times in the EL expression, but is not reused in the case of another EL expression or in the case of a re-evaluation of the same EL expression.

This example is wrapped into the application named ch3_5 that is available in the code bundle of this chapter.

主站蜘蛛池模板: 博罗县| 九江市| 年辖:市辖区| 珲春市| 清远市| 南投县| 右玉县| 德保县| 蓝山县| 白朗县| 屯门区| 五大连池市| 金溪县| 远安县| 古蔺县| 砀山县| 阿城市| 同心县| 阳山县| 永吉县| 井陉县| 绥宁县| 肃宁县| 乌拉特后旗| 神池县| 大埔县| 墨江| 邵阳市| 乡宁县| 金川县| 旌德县| 邻水| 利辛县| 广安市| 同心县| 榆树市| 绵竹市| 乌恰县| 墨竹工卡县| 赣州市| 巫山县|