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?
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 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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With