The container in PicoContainer has the following responsibilities:
The container instantiates a new instance of a component when it is requested. If the component have any dependencies the container looks for and instantiates all of them too.This behaviour can be customized using component adapters, see Extending PicoContainer with ComponentAdapter for more information.
The container stores a reference to the component instance as they are instantiated. You can access this instance using the key that the component was registered with.This behaviour can also be customized using component adapters, see Extending PicoContainer with ComponentAdapter for more information.
The container can also enforce a simple lifecycle (start, stop, dispose) on components contained within it. It is further described on Lifecycle.
Each container can have a parent and a container can also be a component in another container. This effectively creates an hierarchy of containers.
The parent is used for resolving components not found locally. So if a container is looking for a component to resolve a dependency it looks first in locally in it's own container and then looks for the same component in the parent container. The opposite is not true though, a parent container never looks for a component in any of it's child-containers.
By placing a container in a child-container you override the same component if it exists in a sub-container. This is only true for local components or components in child-containers, components placed in a parent-container do not use the overridden component.
Class | Description |
---|---|
PicoContainer | Is an interface that gives you read-only access to components in the container. |
MutablePicoContainer | Is also an interface that extends PicoContainer and also allows components to be registered. |
DefaultPicoContainer | This is the default implementation in the PicoContainer project. |
ImplementationHidingPicoContainer | This is an alternate implementation of MutablePicoContainer. It hides implementations of components where it can |
NanoContainer implementations | There are additional implementations in NanoContainer |