IoC implementation Strategies

Expert one on one J2EE development without EJB:P-128-9

IoC Implementation Strategies
IoC的实现策略

IoC is a broad concept that can be implemented in different ways. There are two main types:
IoC是一个很大的概念,它可以通过不同的方式来实现。最常见的方式有两种:

Dependency Lookup: The container provides callbacks to components, and a lookup context.This is the EJB and Apache Avalon approach. It leaves the onus on each component to use container APIs to look up resources and collaborators. The Inversion of Control is limited to the
container invoking callback methods that application code can use to obtain resources.
依赖查找:容器为组件提供回调接口和一个查找上下文。EJB和Apache Avalon采用的这种方式。这样一来,组件就必须自己使用容器提供的API来查找资源和协作对象,控制反转被限定在容器引用回调方法,由这些方法的代码可以实现获取资源。

Dependency Injection: Components do no look up; they provide plain Java methods enabling the container to resolve dependencies. The container is wholly responsible for wiring up components, passing resolved objects in to JavaBean properties or constructors. Use of JavaBean
properties is called Setter Injection; use of constructor arguments is called Constructor Injection.
依赖注入:组件不自己进行查找,而是提供一般的java方法让容器去解决依赖关系。容器全权负责组件的装配,把符合依赖关系的对象通过javabean属性或构造子传递给需要的对象,通过javabean属性注射依赖的做法叫做Setter注入;通过构造子参数的做法叫做构造子注入。

你可能感兴趣的:(apache,ejb,IOC,UP)