import com.google.inject.Binder; import com.google.inject.Guice; import com.google.inject.Inject; import com.google.inject.Module;
public class ProviderServiceDemo { @Inject private Service service;
public static void main(String[] args) { ProviderServiceDemo instance = Guice.createInjector(new Module() {
@Override public void configure(Binder binder) { binder.bind(Service.class).toProvider(OneServiceProvider.class); } }).getInstance(ProviderServiceDemo.class); instance.service.execute();// Hello! I'M Service 1!
} }
|