Sisu in 5 minutes

Easy-peasy Guice.

Sisu is a set of Guice modules that add classpath scanning, auto-binding, and dynamic wiring. Together these modules make up the Sisu container, but they can also be used individually.

Let's begin with a simple Maven project, paste the following into a file called 'pom.xml'

<?xml version="1.0" encoding="UTF-8"?>


  <name>Sisu 5-minute demo</name>



Sisu looks for types annotated with @Named, binds them, and wires any missing dependencies.

Paste the following code into a file called 'src/main/java/example/'

package example;

import java.awt.*;
import java.util.*;
import javax.swing.*;

// Standard JSR330 annotations
import javax.inject.Inject;
import javax.inject.Named;


// Sisu modules for scanning and wiring
import org.eclipse.sisu.wire.WireModule;

// let's create some simple Swing tabs...

abstract class AbstractTab extends JPanel {}

// Sisu will spot any @Named components

class ButtonTab extends AbstractTab {
  ButtonTab() {
    add(new JButton("Button"));

class CheckBoxTab extends AbstractTab {
  CheckBoxTab() {
    add(new JCheckBox("CheckBox"));

class RadioButtonTab extends AbstractTab {
  RadioButtonTab() {
    ButtonGroup group = new ButtonGroup();
    group.add(new JRadioButton("+1"));
    group.add(new JRadioButton("0"));
    group.add(new JRadioButton("-1"));
    Enumeration<AbstractButton> e = group.getElements();
    while (e.hasMoreElements()) {

// Sisu will launch @EagerSingleton's on startup

class Example implements Runnable {
  JTabbedPane pane = new JTabbedPane();

  // Sisu spots we want a map of tabs and wires it up for us

  Example(Map<String, AbstractTab> tabs) {

    for (Map.Entry<String, AbstractTab> t:tabs.entrySet()) {
      pane.addTab(t.getKey(), t.getValue());


  public void run() {
    JFrame frame = new JFrame("Sisu 5-minute demo");
    frame.add(pane, BorderLayout.CENTER);
    frame.setLocation(100, 50);
    frame.setSize(300, 200);

  public static void main(String[] args) {
    ClassLoader classloader = Example.class.getClassLoader();

      new WireModule(                       // auto-wires unresolved dependencies
        new SpaceModule(                     // scans and binds @Named components
          new URLClassSpace( classloader )    // abstracts class/resource finding

Sisu has a SpaceModule for scanning and a WireModule that wires requests to its dynamic BeanLocator.

Paste the following Maven command into your console window to launch the demo

mvn compile exec:java -Dexec.mainClass=example.Example

If you're interested in what Sisu is doing you can turn on tracing with -Dsisu.debug