Pico Container

# 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

## Ambiguous Injectable

PicoContainer tries to determine what to inject into the constructor of each component as it instantiates (or setters/fields for other injection types). Sometimes there can be two or more classes that could equally satisfy a constructor:

    pico.addComponent(new Apple("Braeburn"));
    pico.addComponent(new Apple("Granny Smith"));
    pico.addComponent(Pie.class); // needs Apple
    Pie pie = pico.getComponent(Pie.class); // throws AmbiguousComponentResolutionException citing there are two Apples.

The best advice is don't setup PicoContainer in a way that would allow ambiguities (just put in one Apple in the case above).

## Strategies to solve this

### Custom Parameters

An alternative strategy would be to use custom parameters (TODO)

### Named Parameters

One more strategy would be to use named parameters

    class Pie {
      Pie(Apple grannySmith) {
        // etc

      }

    }

    ...

    pico.addComponent("braeburn", new Apple("Braeburn"));
    pico.addComponent("grannySmith", new Apple("Granny Smith"));
    pico.as(USE_NAMES).addComponent(Pie.class); // needs Apple, specifically a Granny Smith.
    Pie pie = pico.getComponent(Pie.class); // OK this time.

To use names Parameters, you are going to need Paranamer 1.0 (or above) in the classpath, as well as ASM 3.0 (or above). If you are expecting Pico to work based on parameter names, but its not doing so, it is most likely that you do not have paranamer-1.0.jar in the classpath. See http://repository.codehaus.org/com/thoughtworks/paranamer/paranamer/ for versions of paranamer. Also http://maven.objectweb.org/maven2/asm/asm/ for the ASM jar.

You also have to make a decision as to when parameter name data is made. There are two choices for this:

1. At runtime
2. At build time

When at runtime, PicoContainer will need to be accompanied by ASM and Paranamer in the classpath. You will also need to compile your Java classes with debug information.

When at build time, you will need to use and Ant or Maven fragment to post-process the compiled classes for your app to add the paramaeter name data. At runtime, neither Paranamer nor ASM will be needed. See http://paranamer.codehaus.org/ - specifically the quick start section pertinent to Ant and Maven.