Examples

This is a complete if trivial example using Gravy. It shows how an application can be bootstrapped with an EAGER mapping to the main class which the Context creates when it is started.

The example also shows that, like Pico, Gravy does not require every injected class to have a dependency on the IoC library. (This is a problem with Guice -- all your injected classes need to import a Guice annotation). The only class having a dependency on Gravy is the one that creates the Context.

package com.babblemind.simple;

import com.babblemind.gravy.Context;

public class Example01 {
    public static void main(String args[]) {
	Context context = new Context();
	context.wire(Widget.class).
	    to(WidgetImpl.class).
	    with(Context.Option.EAGER);
	context.start();
    }
}

package com.babblemind.simple;

public interface Widget {
}

package com.babblemind.simple;

public class WidgetImpl implements Widget {
    public WidgetImpl() {
	System.out.println("A WidgetImpl was created");
    }
}

There is a larger example which creates multiple instances of a Swing GUI in the source distribution.