Skip to end of metadata
Go to start of metadata

Authors: Paul Hammant, Jon Tirsen


Lifecycle is one third of Inversion of Control. Lifecycle concerns the post composition life of the component. Start, stop and dispose are the most commonly encountered lifecycle concepts.

No Lifecycle

For really simple PicoContainer compatible components, you would not bother with a lifecycle beyond instantiation and garbage collection - both of which are consequences of basic use of say DefaultPicoContainer. This is the vast majority of Pico components in the vast majority of applications.



Aggregated View

It might be common to see a tree of components and containers in a advanced application. If one of the lifecycle methods is invoked on the root container, it is in turn invoked on all child containers and components where is is appropriately implemented. The starting of components is handled breadth The stopping and disposing of containers and components is handled depth first, and in reverse order to instatiation.

Simple lifecycle

PicoContainer provides two very simple interfaces for lifecycle:
Startable and Disposable.

These interfaces honours the classic lifecycle concepts for components. These are start(), stop() and dispose(). If any of the components implements one of the applicable interfaces, the calling of the same method on the container will find that the call is percolated through to it. The container is forgiving, as it is just fine if some or none of the components contained are Startable etc.





Components can sometime implement start/stop, but not those mandated by an the PicoContainer lifecycle interface:



In this scenario, a simple extension can make the component honour the PicoContainer lifecycle interface:



Delegation is also a neat way of adapting the component:



Custom lifecycles

(info) The following functionality has been moved to NanoContainer-Proxytoys

Custom lifecycle management is a common requirement for components. Probably because it is so crucial, there are many competing implementations. Each has its own passionate group of advocates.

PicoContaioner tries to avoid controversy by being partially agnostic about the lifecycle/lifecycles that it supports. As detailed previously, PicoContainer does have an implementation of a simple lifecycle and this is supported in the default container.

Instead of mandating PicoContainer's lifecycle interface, we provide a plug-in that should grant compatibility with other lifecycle concepts. Consider this custom interface:





  • No labels


  1. TODO
    This document is not up-to-date with the current codebase. We need to use {snippet} here.
    I think we should also change the example to be more concrete, so that it outlines a common usage of lifecycle in the real world.

  2. Code should be uptodate now. I agree we should move to snippet and give a more concrete example though. Anyone got one?