Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

So as per this tutorial, we can bind only one implementation at a time? What if I need to use FacebookMessageService AND EmailMessageService? How to handle that?
- Farhad
Hello! Can you please point discrepancies with this approach? I see one: @Singleton annotation. Thank you!
- Igor
property-based injection seams to work as well: public class RestResource { @Inject private IemandsService service; works like a charm
- Mark Muizer
You can use assertTrue(…) instead of assertEquals(true, …)in your test. Looks better :)
- Rafal
Thank you Pankaj, This is my third tutorial of yours that I have gone through and I think they are very well written.
- David Adkins
My Main java class: =================== package com.sample.test; import com.google.inject.Guice; import com.google.inject.Injector; public class mymain { public static void main(String[] args) { // TODO Auto-generated method stub Injector injector = Guice.createInjector(new AppInjectory()); ApplicationExample obj = injector.getInstance(ApplicationExample.class); obj.sendMessage(); } } My interface ============= package com.sample.test; public interface MessageService { boolean sendMessage(String msg, String receipient); } My config file ================== package com.sample.test; import com.google.inject.AbstractModule; public class AppInjectory extends AbstractModule { @Override protected void configure() { //bind the service to implementation class //bind(MessageService.class).to(EmailService.class); //bind MessageService to Facebook Message implementation bind(MessageService.class).to(EmailService.class); } } My appication file =================== package com.sample.test; import javax.inject.Inject; public class ApplicationExample { private MessageService service; @Inject public void setService(MessageService svc){ this.service=svc; } public void sendMessage() { System.out.println(“I am here”); service.sendMessage(“welcome”, “java”); } } My service class ===================== package com.sample.test; //import com.google.inject.Singleton; import javax.inject.Singleton; @Singleton public class EmailService implements MessageService { public boolean sendMessage(String msg, String receipient) { //some fancy code to send email System.out.println(“Email Message sent to “+receipient+” with message=”+msg); return true; } } Here I am getting NUll pointer exception .What wrong I did here.?please help to fix this issue. ERROR: Exception in thread “main” I am here java.lang.NullPointerException at com.sample.test.ApplicationExample.sendMessage(ApplicationExample.java:16) at com.sample.test.mymain.main(mymain.java:13)
- lawri
Thank you ! Guice for human arrived ! I used it for other projects but this time I found a really good introduction to understand the bases.
- sbeex