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?
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).

- 37,782
- 12
- 108
- 140

- 14,039
- 5
- 40
- 55
-
Jan, thanks for your very helpful answer. You mention @In and @Out are Seam 2 annotations, are they deprecated in seam 3? – arg20 Apr 05 '11 at 04:31
-
More than that - they are not available. They are part of the Seam 2 jar, and this library is not deployed in JEE 6, so you cannot use them at all. – Jan Groth Apr 05 '11 at 04:59
-
1Seam2 != Seam3 Only the names are the same. Seam3 is a complete new implementation. – Dar Whi Aug 30 '11 at 02:03