Scope equivalent to @Stateless on CDI

Asked

Viewed 252 times

4

I’m migrating the notes EJB from my application to CDI and I have some doubts:

  • What is the equivalent scope @Stateless of the EJB at the CDI?
  • The @ResquestScoped would act in an equivalent manner?
  • I did tests using @Stateless injecting with CDI using @Inject, that is correct?

I am migrating a service class that only receives the requests from my managedBean and passes the information to the persistence class and does not need to keep its scope alive.

2 answers

1


Except with the use of some extension, there is nothing 100% equivalent in CDI.

Despite this, Requestscoped can serve well for many cases, remembering that Ejbs also control transactions (they have created new annotations for transactions in CDI 1.1 or 1.2) and have a lifecycle that reuses instances (from a pool) instead of creating new ones. If those little differences don’t get in the way,.

The use of Inject, at first (without seeing the code), seems correct.

This article http://blog.dblevins.com/2012/11/cdi-when-to-break-out-ejbs.html indicates features that exist in EJB but not in CDI, but does not include novelties created after CDI 1.0.

  • Excellent answer, I will wait one more day to see the next answers, but I already defer my thanks and if no one responds better the reward is yours. Thank you!

1

What better fits to replace the @Stateless using the ICD is the @RequestScoped.

The concept of stateless is consider each request as an independent transaction that is not related to any previous request.

Already the @Requestscoped it acts as a simple HTTP request, is dropped after each request, Managedbean will not maintain its status between HTTP requests/requests that the user makes.

So the best option is himself.

Stop complementary, I usually use quite the @Viewscoped as it maintains the status while the user stays on the page, being a middle between @RequestScoped and @SessionScoped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.