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: Completed usage of Pico in IzPack

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

Two injections methods have been used primary used.

...

The advantages of dependency injection are numerous

  • Unloads your code from managing instance creation. You don't need to use the new keywords in your code, simply ask for the dependency.
  • Minimize coupling between classes

Specifically to IzPack, PicoContainer allows

  • No more singletons.
  • Better testing. Integration testings were possibles thanks to dependency injection.
  • Better support for dynamic construction. Panels and listener were build using reflexivity with fixed constructor. Now, they are instantiated with picoContainer thus you don't need a fixed constructor anymore. In fact, you can now obtain any of IzPack component by "asking" it in the constructor.

How to inject dependencies

Dependencies definitions

With pico, you create and manage your own container. Once created, you can

...

Here you create a new container, add CliAnalyzer as a dependency and get an the instance of CliAnalizer.
The container is configured to "cache" dependencies. Meaning, it insures that there is only one instance of this component created. It is the same as a Singleton in Guice.

Expect some particular cases, you don't need to lookup for your component using the container. Exceptions are when component are constructed dynamically like panels. In this case, we add the panel and get the instance from the compiler.

In most case, you should use injection to get dependencies.

Injection methods

Two injections methods have been used primary used.

  1. Injection by constructor.
  2. Injection by provider
Injection by constructor :

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

...

It is used to create component which need informations from xml (like AutomatedInstallData). All providers are avaible available in packages *.container.provider

...

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

How to add a component in IzPack

If you create a component, you can add it to the container and different components.so that it will be avaible as a dependency.

On the compiler, the container is configured by the class com.izforge.izpack.compiler.container.CompilerContainer

On the installer, there are several containers : 

  • com.izforge.izpack.installer.container.impl.ApplicationContainer : Global container
  • com.izforge.izpack.installer.container.impl.CustomDataContainer :Specific container for customData. Child of ApplicationContainer
  • com.izforge.izpack.installer.container.impl.InstallerContainer : Container for panel and frame. Child of ApplicationContainer