PicoContainer

# About

- What is PicoContainer?
- Introduction
- Javadoc
- Downloads
- News
- FAQ
- Project Goals
- Support

# Core Concepts

- Component Lifecycle
- Dependency Injection
- Scoped Containers

# Dependency Injection

- Constructor Injection
- Setter Injection
- Annotated Field Injection
- Annotated Method Injection
- Typed Field Injection
- Named Field Injection
- Method Injection
- Multiple Injection
- Composite Injection
- Factory Injection
- Reinjection
- Injection via Providers

# Configuration

- Disambiguation

# Modifying Component Behaviors

- Modifying Behaviors
- Caching and Singletons
- Hiding Implementations
- Thread Safety Behaviors
- AOP Style Interception

# Advanced Concepts

- Fluent Style
- Arrays, Collections and Maps
- Leveraging Parameter Names
- Building Containers
- Component Properties
- Component Configuration
- Monitoring Component Events

# PicoContainer's Architecture

- Design Patterns
- Inversion of Control
- Component Adapters
- Mock Objects
- Terminology
- Container Comparisons
- Transparency

# Container Choices

- DefaultPicoContainer
- CommandLinePicoContainer
- PropertiesPicoContainer
- SystemPropertiesPicoContainer
- TransientPicoContainer
- TieringPicoContainer

# Dependant & Related

- Web Frameworks
- Scripting Support
- Persistence
- Logging

# Anti-patterns

- Propagating Dependency
- Long Constructor Argument List
- Container Dependency
- Unit Tests Use Container
- Singleton

# Help Pages

- Ambiguous Injectable
- Unprocessed Properties

# History

- Inversion of Control History

# Project Info

- Project
- Team

# Hosted by

# Tools

## Building Containers

Rather than new up a PicoContainer instance with the right ComponentFactory, LifecycleStategy and ComponentMonitor, your can use PicoBuilder for conveniece. Refer to Martin Fowler's 'Fluent Interface' article, for some of the motivation behing this class.

Some simple examples :

    pico = new PicoBuilder().build();
    pico.addComponent(Apple.class);

    pico = new PicoBuilder().withCaching().build();
    pico.addComponent(Apple.class);

    pico = new PicoBuilder().withCaching().build();
    pico.addComponent(Apple.class);

    pico = new PicoBuilder().withHiddenImplementations().build();
    pico.addComponent(Apple.class);

More varations for behaviors :

    pico = new PicoBuilder().withLifecycle().withConsoleMonitor().build();
    pico.addComponent(Apple.class);

    pico = new PicoBuilder().withMonitor(ConsoleComponentMonitor.class).build();
    pico.addComponent(Apple.class);

    import static org.picocontainer.injectors.Injectors.SDI;
    import static org.picocontainer.behaviors.Behaviors.caching;
    import static org.picocontainer.behaviors.Behaviors.implementationHiding;
    import static org.picocontainer.behaviors.Behaviors.synchronizing;
    ...
    pico = new PicoBuilder(SDI()).withBehaviors(caching(), implementationHiding(), synchronizing()).build();
    pico.addComponent(Apple.class);

Setting a parent container :

    child = new PicoBuilder(parentContainer).build();
    child.addComponent(Apple.class);

Specifying an injection type:

    pico = new PicoBuilder().withAnnotationInjection().build();
    pico.addComponent(Apple.class);

Specifying an injection type a different way:

    import static org.picocontainer.injectors.Injectors.SDI;
    ...
    pico = new PicoBuilder(SDI()).build();
    pico.addComponent(Apple.class);

A custom container component used by a custom ComponentBehavior (though could be used by ComponentMonitor or LifecycleStrategy as easily):

    pico = new PicoBuilder()
        .withCustomContainerComponent(new MyQuantumPhysicsConnector())
        .withComponentFactory(MyQuantumPhysicsConnectionNeedingComponentBehavior.class).build();
    pico.addComponent(Apple.class);

A custom container implementation (DefaultPicoContainer is the default):

    MyCustomPicoContainer pico = (MyCustomPicoContainer) new PicoBuilder().implementedBy(MyCustomPicoContainer.class).build();
    pico.addComponent(Apple.class);