0
votes

If an EJB is injected by CDI container using @Inject, because that CDI has scope, that means this EJB will have scope and it's lifecycle will be controlled by CDI container instead of EJB container?

Or the CDI container only injects and the lifecycle is controlled by EJB container?

For example: I implement a SLSB which has it's lifecycle controled by EJB container. It means that the EJB container will control the creation, pooling and destruction of the bean.

By default CDI bean has Dependent scope. If I inject this SLSB using @Inject CDI will control the bean's lifecycle so that it will be created and destroyed every time the parent class is created and destroyed? If that is true the EJB lost the concurrence characteristics (pool of bean).

1
You might find this interesting. - Martin Andersson
Thanks. I read the CDI specification mentioned in your link and found what I was looking for: "A stateless session bean must belong to the @Dependent pseudo-scope. A singleton session bean must belong to either the @ApplicationScoped scope or to the @Dependent pseudo-scope. If a session bean specifies an illegal scope, the container automatically detects the problem and treats it as a definition error. A stateful session bean may have any scope." - Marcelo Keiti
See if you can answer this question =). - Martin Andersson
Sorry, I don't understand why there are 2 scopes allowed for @Singleton too =( - Marcelo Keiti

1 Answers

1
votes

From bkail's answer on a similar question:

The @Inject version will respect the scope of the EJB. For example, using @EJB to inject an SFSB into a servlet makes no sense because only one SFSB will exist for every request. Using @Inject to inject a @SessionScoped SFSB into a servlet means you have a CDI proxy that creates a new SFSB as needed for each session.