User Documentation

One minute description
Two minute tutorial
Five minute introduction
Advanced Topics
FAQ
Container
Components
Terminology
Mock Objects
Inversion of Control Types

Patterns

Inversion of Control 
Dependency Injection 
Constructor Injection 
Setter Injection 
Interface Implementation Separation 
Lifecycle 
Antipatterns

Developer Documentation

 Current build status
How To Contribute
Relative Volunteering
Release Process

Project Information

Slogan
Mailing lists
Source Repositories
Open Issues
Blog entries 
Statistics
Team
Sister Projects
TShirts

Miscellaneous

Differentiators
Nirvana

Full Sitemap

Feeds


Site
News
Container

The container in PicoContainer has the following responsibilities:

  • instantiating and assembling components through Dependency Injection,
  • storing component instances accesible by keys,
  • maintaining a components lifecycle,
  • delegating to the parent for components not found locally.

Assembling components

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.

Storing component instances

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.

Maintaining lifecycle

The container can also enforce a simple lifecycle (start, stop, dispose) on components contained within it. It is further described on Lifecycle.

Container hierarchies

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.

API Overview

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