View/Hide Sitemap Inline ...

Component Properties

DefaultPicoContainer allows for some properties to be set per component at the time each is added. A convenience class called Characteristics lists the supplied properties.

Properties can be set for a component in a method ‘as’ on MutablePicoContainer. If that is the case then the properties will affect the next component added only.

They can also be set in a more persistent manner for the MutablePicoContainer in question, using the ‘change’ method. If so, they will affect all subsequent additions of component.

Some examples :

import static org.picocontainer.Characteristics.SDI;
import static org.picocontainer.Characteristics.CACHE;
pico = new DefaultPicoContainer();;, SDI).addComponent(Pear.class);
import static org.picocontainer.Characteristics.SDI;
import static org.picocontainer.Characteristics.CACHE;
pico = new DefaultPicoContainer();

pico = new DefaultPicoContainer();;, Characteristics.SDI).addComponent(Pear.class);

pico = new DefaultPicoContainer();

Some characteristics are mutually exclusive. For example CDI, SDI. Meaning the last one set via ‘as’ or ‘change’ rules. Others are additive like CACHE and HIDE_IMPL. The order of these is not important.

Appropriate Behavior and Injection Factories.

Every characteristics set for a component must be handled by a BehaviorFactory or InjectionFactory that recognizes it. They are typically chained together. DefaultPicoContainer’s default BehaviorFactory and InjectionFactory are AdaptiveBehaviorFactory and AdaptiveInjectionFactory. These can handle CDI and SDI as well as CACHE and HIDE_IMPL.

If you setup DefaultPicoContainer with a BehaviorFactory/InjectionFactory combination that is unaware of the characteristics you subsequently use, Pico will object by way of an exception as you add the component to the container. See Unprocessed Properties .

Supplied properties (from org.picocontainer.Characteristics) -

Custom Properties

You can make your own properties quite easily – check out the source to and the classes that refer to it in PicoContainer (various implementations of ComponentFactory and ComponentAdapter).