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

## Annotated Field Injection

### Injecting into Annotated Fields

This is where a component has an empty constructor with dependencies indicated by a field annotation and provided automatically by the container after instantiation.

    public class Apple {
        @Inject
        private Orange orange;
        @Inject
        private Pear pear;
        @Inject
        private Banana banana;
        // methods
    }

#### Usage

    pico = new DefaultPicoContainer(new AnnotatedFieldInjection();
    pico.addComponent(Apple.class);
    // etc
    Apple apple = pico.getComponent(Apple.class);

With an custom annotation instead of PicoContainer's @Inject

    pico = new DefaultPicoContainer(new AnnotatedFieldInjection(MyInjectAnnotaton.class);
    pico.addComponent(Apple.class);
    // etc
    Apple apple = pico.getComponent(Apple.class);

Yes that's right, there's no constructor needed. It means that for a Unit Test, you cannot simply 'new' the class without some magic to populate the dependency fields.

The component factory for this is a class AnnotatedFieldInjection. It only handles annotation-field injection for components.

Additionally the default component factory AdaptiveInjection can also handle field annotation types, if the @Inject annotation from PicoContainer's code-base is used as the marker for injection. AdaptiveInjection will also fall through to constructor injection if there is no recognized @Inject annotation.