title: Guice: Binding several objects with different dependencies
body: <p>I have the following code using Guice bindings:</p>
  
  <pre><code>public class MyApplication {
      public static void main(String[] args) {
          Guice.createInjector(new AbstractModule() {
              @Override
              protected void configure() {
                  bind(Foo.class).annotatedWith(Names.named("first")).toInstance(new Foo("firstFoo"));
                  bind(Foo.class).annotatedWith(Names.named("second")).toInstance(new Foo("secondFoo"));
  
                  bind(Bar.class).to(BarImpl.class);
  
                  bind(MyApplication.class).asEagerSingleton();
              }
          });
      }
  
      private @Named("first") Bar first;
      private @Named("second") Bar second;
  
      static @Value class Foo { String name; }
      static interface Bar {}
  
      static class BarImpl implements Bar {
          @Inject @Named Foo foo;
      }
  }
  </code></pre>
  
  <p>I'm trying to get a <code>Bar</code> object for both named <code>Foo</code>s injected in my application. Basically, it should somehow connect the <code>@Named</code> on <code>Foo</code> with the one on <code>Bar</code>. I have tried several solutions, from putting <code>@Named</code> on everything to writing a custom <code>Provider</code>. The latter didn't work because I don't have access to the value of the <code>@Named</code> annotation inside the provider. I think the solution is somewhere in the line <code>bind(Bar.class).to(BarImpl.class);</code>, telling it to remember the value of the <code>@Named</code> annotation.</p>
  
  <p>My question is, is this possible at all, and if so, how?</p>