Skip to content

Latest commit

 

History

History
34 lines (27 loc) · 781 Bytes

multi-injection.md

File metadata and controls

34 lines (27 loc) · 781 Bytes
layout title
article
Multiple Injection

Overview

This is where a component has is a blend of one or more of Constructor, Setter, Method, Annotated Field etc:

public class Apple {
  private Orange orange;
  private Pear pear; @Inject private Banana banana;
  public inject(Orange orange) {
    this.orange = orange;
  }
  public void inject(Pear pear) {
    this.pear = pear; 
  } 
  // other methods 
}

Usage

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

In the case above, Orange comes in through the constructor, Pear by method injection and Banana is via Annotated Field Injection.

The component factory for this is MultiInjection .