title: How to create an instance of an implementation in Google Guice
body: <p>I'm new to Google Guice and need a little help. I have created a module like this:</p>
  
  <pre><code>public interface Foo {
    Bar doSomething();
  }
  
  public class MyFoo implements Foo {
    Bar doSomething() {
      // create an instance of MyBar
    }
  }
  
  public interface Bar {
    void run();
  }
  
  public interface MyBar implements Bar {
    void run();
  }
  
  public class MyModule extends AbstractModule {
  
    @Override
    protected void configure() {
      bind(Foo.class).to(MyFoo.class);
    }      
  }
  </code></pre>
  
  <p>My question is: What is the right way to create an instance of MyBar in class "MyFoo"? It feels wrong to just do this:</p>
  
  <pre><code>public class MyFoo implements Foo {
    Bar doSomething() {
      MyBar mybar = new MyBar();
      return mybar;
    }
  }
  </code></pre>
  
  <p>Is there a way to inject a new instance of MyBar by MyModule when I need one, or do I have to inject a factory in the constructor of  MyBar for creating MyBar instances?
  If I have to use a factory, can I control which implementation is generated via the module?</p>