gpt4 book ai didi

java - CDI(上下文和依赖注入(inject))和DI(依赖注入(inject))有什么区别

转载 作者:行者123 更新时间:2023-11-30 02:18:31 25 4
gpt4 key购买 nike

官方文档说

The most fundamental services provided by CDI are as follows:
  • 上下文:能够将有状态组件的生命周期和交互绑定(bind)到定义明确但可扩展的生命周期上下文
  • 依赖注入(inject):能够以类型安全的方式将组件注入(inject)到应用程序中,包括在部署时选择要注入(inject)特定接口(interface)的实现的能力

但我还是没明白其中的区别。例如Spring就是DI,我们仍然可以访问其中的上下文。

最佳答案

CDI gives you more opportunities. And provide it in some different way that Spring - is trying to rest more on the possibility of verification at compile time. But sometimes it is look like overhead. In a very small project EJB plus DI from JSF for example will be quite enough. But you can use CDI, only first it is worth reading more carefully about the main advantages in comparison with EJB's DI. There are many little details and you must think about where to use it.

我从“https://javatalks.ru/topics/40299”中获取它并为您翻译最接近的答案。我建议您阅读以下内容:“https://blogs.oracle.com/enterprisetechtips/using-cdi-and-dependency-injection-for-java-in-a-jsf-20-application”这是 Oracle 工程师关于使用 CDI 和 DI 的好文章

关于java - CDI(上下文和依赖注入(inject))和DI(依赖注入(inject))有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47551056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com