package cruzgtug.example.guice; import com.google.inject.AbstractModule; import com.google.inject.Provides; import com.google.inject.name.Named; /** * Encapsulates all Guice bindings used by HelloExample * * @author esmiley * */ public class HelloModule extends AbstractModule { /** * This specifies what bindings this module provides */ @Override protected void configure() { /* * This tells Guice that whenever it sees a dependency on a Hello, it should * satisfy the dependency using a HelloImpl. */ bind(Hello.class).to(HelloImpl.class); } /** * If the @Provides method has a binding annotation like @PayPal or * @Named("BusinessAddress"), Guice binds the annotated type. * Dependencies can * be passed in as parameters to the method. The * injector will exercise the bindings for each of * these before invoking the method. * * @return the string */ @Provides // this is a provider method @Named("HelloString") // this is a named string String provideHello() { return "Hello from Guice."; } }