焊缝双射和焊接

发布于 2024-10-30 13:45:59 字数 121 浏览 0 评论 0原文

我正在开发一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧情别恋 2024-11-06 13:45:59

@In 和 @Out 注释仍然存在吗
现在我们有 CDI 了吗?

@In@Out 是 Seam 2 注释,因此在 Java EE 6 中不使用它们。

我的问题是,@Inject 和
@Producs 与 @In 和 @Out 相同
接缝?

@Inject@Produces 并不完全相同,但它们大致相当。主要区别在于,Java EE 6 依赖项是在需要时生成的(由需要依赖项的组件控制),而在 Seam 2 中,一旦准备好使用,就会执行喷射 其他地方(由提供依赖的组件控制)

以登录为例:

  • 在 Seam 2 中,经过身份验证的用户在成功登录后立即被注入到所需的范围(如会话)。登录组件本身具有通常适合用例(对话)的范围,但不适合所提供的依赖项(会话)的范围。
  • 在 Java EE 6 中,会话范围的登录组件执行身份验证并将经过身份验证的用户存储在私有字段中。然后该字段由生产者方法控制。因此,每当另一个组件请求经过身份验证的用户时,就会执行类似的操作:

     @Produces @LoggedIn User getCurrentUser() {
          返回用户;
       }
    

为什么会这样?我听到你问...

原因很简单。 Weld / Java EE 6 由于能够代理(大多数)依赖项而获得了巨大的性能提升。而且根本不可能代理喷射:-)

好吧,除此之外:Java EE 6 面向需求的方法(在需要时请求它)感觉优于 Seam 2(生成它并存储它)。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文