I recetly moved from playing around with component adapters to component lifecycle, and I made little investigation about the mysterious addOrderedComponentAdapter() method. I discovered that it is called from InstantiatingComponentAdapter, CachingComponentAdapter and DefaultPicoContainer, on behalf of InstanceComponentAdapter.
This does not seem right to me, especially with the DecoratingComponentAdapter floating around (which I happen to use).
I made a number of modifications to Pico with the following goals in mind:
- addOrderedComponentAdapter(..) must be called for each component instantiated in the system, no matter wich type of adapter performs the instantiation
- the instantiationOrderedComponentAdapters must contain only one entry per component (note that more than one adapter may participate in instantiating an object)
I needed to make the following changes in MutablPicoContainer API
- added componetnKey parameter to the addOrderedComponentAdapter(..) method, to relate together various adapters that participate in instantiation of a component
- added a registerOrderedComponentAdapter(..) method, that must be called before add... The adapter that calls this methods first, becomes the orderedAdapter for the component.
After these changes, ordered adapter registeration is performed in these classes:
InstanceComponentAdapter
InstantiatingComponentAdapter
DecoratingComponentAdapter
CachingComponentAdatper
SynchronizedComponentAdapter
the last two can be gotten rid of, provided that we make them extend DecoratingComponentAdapter, I decided file a separate issue for that, to keep the patch simpler.
a patch introducing described changes