We need you!

Icon

The IzPack documentation needs work, and you are invited to edit it!

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: FIxed URL for picocontainer.

PicoContainer is a mature dependency injector framework similar to spring-core or Guice. It presents the advantage to be quite small (~260Ko) and yet very complete.

...

  • Add component to the container
  • Get component from the container
Code Block
borderStylesolid
titleCompilerContainer.java
borderStylesolid
pico = new PicoBuilder().withConstructorInjection().withCaching().build();
pico.addComponent(CliAnalyzer.class);
CliAnalyzer cliAnalyzer = pico.getComponent(CliAnalyzer.class);

...

Injection by constructor :

(see http://www.picocontainer.codehaus.org/constructor-injection.html)
PicoContainer supports many types of injections but the preferred way is to pass dependencies in the constructor.

For example, given the following class :

Code Block
borderStylesolid
titleAClass.java
borderStylesolid
public class AClass {
 public AClass(CliAnalyzer cliAnalyzer){
  // Use cliAnalyzer
 }
}
Code Block
borderStylesolid
titleCompilerContainer.java
borderStylesolid
pico = new PicoBuilder().withConstructorInjection().withCaching().build();
pico.addComponent(CliAnalyzer.class);
pico.addComponent(AClass.class);
AClass aClass = pico.getComponent(AClass.class);

...

Injection by provider :

(see http://www.picocontainer.codehaus.org/providers.html)
Provider gives more flexibility to construct the component instance and it is useful to do some works prior to instantiation.

...

Injection of primitives :

(see http://www.picocontainer.codehaus.org/component-configuration.html)
PicoContainer gives the possibilities to inject primitives (String, Integer, ...). They are resolved by name and it is used to inject the install file name in components.

...