AgE 2.7 : (T) IoC Container

On this page:

Container implementation

The IoC container used in AgE is based on PicoContainer .

The container is basically a registry of components, in which they can be looked up by name or by type.

Most implementation features are well described in PicoContainer documentation and need not be covered here. These include:

A few notable customizations are as follow:

  • only component definitions can be added to the container. The container will create adapters out of such definitions.
  • custom injector implementations provide a custom dependency injection (see below).

Dependency injection

The dependency injection process have been customized, by implementing custom injectors, as follows:

  • constructor injection based on explicit arguments, if present, or autowiring
  • autowiring fields and methods, unless conflicting property explicit arguments are provided
  • property injection
  • interface injection (InstanceProviderAware - which allows to inject the container itself).
  • current lifecycle callbacks from StatefulComponent are called

There are also dedicated injectors for array, collection and map components.

Component scope

There are two component scopes: prototype and singleton. The former means that for a given component name, each retrieved instance will be unique. The latter means that each successive instance will be the same.

Singleton scoping is achieved by using PicoContainer Cache behavior, which decorates the actual adapter and cache the returned instance.

Component shadowing

Component shadowing is implemented in the following way: If a component definition have other nested one, a new child container is created and added to the current one. All inner definitions are then added to the child container.

The adapter for that component is added to the parent container, but any dependencies will be resolved using the child one. That way, any inner components, resolved by the child container, will shadow the components present in the parent container.

This process is repeated recurrently and result in a container hierarchy reflecting the configuration.