CDI中的上下文是什么意思? [英] what is meant by context in CDI?

查看:75
本文介绍了CDI中的上下文是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是CDI的新手。在阅读时,我总是遇到上下文对象,非上下文对象。它们是什么意思?

I am new to CDI. While reading, I am always encountering contextual objects, non contextual objects. What does they mean?

例如下面的链接

http://docs.jboss.org/weld/reference/latest/en-US/html /beanscdi.html#d0e881


消息驱动和实体bean本质上是非上下文对象
和可能不会注入其他对象

Message-driven and entity beans are by nature non-contextual objects and may not be injected into other objects


推荐答案

CDI框架的上下文基本上很大对象图*。您可以使用任何CDI配置方法(spring xml bean /注解,如@ Component / @ Service),将对象添加到上下文中,或使CDI框架从服务类中创建对象。

The context of a CDI framework is basically a big map of objects*. You can add objects to the context or make the CDI framework create objects from your service classes by using any CDI configuration method (spring xml beans/annotations like @Component/@Service).

一旦有了上下文,就可以从中获取对象:(Spring:getBean(name))

Once you have the context you can get objects from it: (Spring: getBean(name))

现在,您可以在对象中配置对象/ bean之间的依赖关系了。上下文,并且CDI将确保从上下文中获取的任何对象都将设置其依赖项。这是依赖性注入部分。

Now you can configure dependencies between the objects/beans in the context, and the CDI will make sure any object you get from the context will have its dependencies set. This is the dependency injection part.

非上下文对象只是不添加到上下文中,CDI框架也不了解它们。通常只有服务类是CDI上下文的一部分。

Non-contextual objects are simply not added to the context and the CDI framework does not know about them. Usually only service classes are part of the CDI context.

*虽然不是真正的地图,但是可以通过名称,类型和其他方式访问对象。默认值是每次使用相同的名称(单例)询问时都会得到相同的对象,尽管您可以配置CDI在每次询问时(原型)创建一个新对象。

* Not really a map though, objects can be accessed by name, by type and other ways. The default is you get the same object each time you ask by the same name (singleton), although you may configure the CDI to create a new object each time you ask (prototype).

这篇关于CDI中的上下文是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆