焊缝双射和焊接
我正在开发一个 JAVA EE 6 应用程序。我广泛使用 CDI,我的问题是,@Inject 和 @Produces 与 Seam 的 @In 和 @Out 相同吗?既然我们有了 CDI,@In 和 @Out 注释仍然在使用吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@In
和@Out
是 Seam 2 注释,因此在 Java EE 6 中不使用它们。@Inject
和@Produces
并不完全相同,但它们大致相当。主要区别在于,Java EE 6 依赖项是在需要时生成的(由需要依赖项的组件控制),而在 Seam 2 中,一旦准备好使用,就会执行喷射 其他地方(由提供依赖的组件控制)以登录为例:
在 Java EE 6 中,会话范围的登录组件执行身份验证并将经过身份验证的用户存储在私有字段中。然后该字段由生产者方法控制。因此,每当另一个组件请求经过身份验证的用户时,就会执行类似的操作:
为什么会这样?我听到你问...
原因很简单。 Weld / Java EE 6 由于能够代理(大多数)依赖项而获得了巨大的性能提升。而且根本不可能代理喷射:-)
好吧,除此之外:Java EE 6 面向需求的方法(在需要时请求它)感觉优于 Seam 2(生成它并存储它)。
@In
and@Out
are Seam 2 annotations, so they are not used in Java EE 6.@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:
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).