How do I bind Different Interfaces using Google Guice?

Posted by kunjaan on Stack Overflow See other posts from Stack Overflow or by kunjaan
Published on 2010-05-08T20:55:13Z Indexed on 2010/05/09 23:18 UTC
Read the original article Hit count: 214

Do I need to create a new module with the Interface bound to a different implementation?

Chef newChef = Guice.createInjector(Stage.DEVELOPMENT, new Module() {
     @Override
      public void configure(Binder binder) {
        binder.bind(FortuneService.class).to(FortuneServiceImpl.class);
      }

    }).getInstance(Chef.class);

Chef newChef2 = Guice.createInjector(Stage.DEVELOPMENT, new Module() {
  @Override
  public void configure(Binder binder) {
    binder.bind(FortuneService.class).to(FortuneServiceImpl2.class);
  }

}).getInstance(Chef.class);

I cannot touch the Chef Class nor the Interfaces. I am just a client binding to Chef's FortuneService to different Interfaces at runtime.

© Stack Overflow or respective owner

Related posts about google-guice

Related posts about guice