Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seam bijection and Weld

I'm developing a JAVA EE 6 app. I'm using CDI extensively, My question is, are @Inject and @Produces the same as @In and @Out for Seam? Are @In and @Out annotations still used now that we have CDI?

like image 452
arg20 Avatar asked Apr 03 '11 21:04

arg20


1 Answers

Are @In and @Out annotations still used now that we have CDI?

@In and @Out are Seam 2 annotations, so they are not used in Java EE 6.

My question is, are @Inject and @Produces the same as @In and @Out for Seam?

@Inject and @Produces are not exactly the same but they are roughly equivalent. The main difference is that Java EE 6 dependencies are produced when required (controlled by the component which requires the dependency), while in Seam 2 outjection was performed as soon as something was ready to be used somewhere else (controlled by the component which provides the dependency)

Take a login as example:

  • in Seam 2, the authenticated user was outjected into the desired scope (like session) immediately after having successfully logged in. The login component itself had a scope which usually fits the usecase (conversation), but not the scope of the provided dependency (session).
  • in Java EE 6, a session-scoped login-component performs the authentication and stores the authenticated user in a private field. This field is then controlled by a producer method. So whenever another component requests the authenticated user, something like this is performed:

      @Produces @LoggedIn User getCurrentUser() {
          return user;
       }
    

Why is that? I hear you asking...

The reason is quite simple. Weld / Java EE 6 gains a huge performance boost from being able to proxy (most) dependencies. And it's simply not possible to proxy outjections :-)

Well, apart from that: the Java EE 6 demand-orientated approach (request it when you need it) feels superior to Seam 2 (produced it and store it away).

like image 152
Jan Groth Avatar answered Jan 03 '23 12:01

Jan Groth