Service.java
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public interface Service { public void test(); }
AService.java
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public class AService implements Service { public void test(){ System.out.println("A tested!"); } }
Module.java
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import com.google.inject.AbstractModule; public class Module extends AbstractModule { public void configure() { bind(Service.class).to(AService.class); } }
TestGuice.java
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import com.google.inject.Guice; import com.google.inject.Injector; import org.junit.Test; public class TestGuice { @Test public void test() { Injector injector = Guice.createInjector(new Module()); Service service = injector.getInstance(Service.class); service.test(); } }