title: Google Guice return new instance every time
body: <p>I am newbie to Dependency Injection and had to learn both Spring and Guice recently. The question below may be pretty lame.</p>
  
  <p>Spring lets you create prototype objects with @Scope("prototype") annotation meaning a new object is returned every time</p>
  
  <p>Eg in my spring container:-</p>
  
  <pre><code>@Scope("prototype")
  @Bean
  A getA(){
     return new A();
  }
  </code></pre>
  
  <p>And a new object A is injected in all references of @autowired.</p>
  
  <pre><code>class B {
    @Autowired
    A objA;
  }
  </code></pre>
  
  <p>However, in guice injector, the same instance is being injected. Looks like guice provides only singleton, request or session scopes <a href="https://github.com/google/guice/wiki/Scopes" rel="nofollow noreferrer">https://github.com/google/guice/wiki/Scopes</a>. My application is not exactly a web service and am wondering how to inject new instances of the object everywhere. I read provider could be used, but couldn't find any lame/easy examples to understand.</p>
  
  <p>How could I inject new instances of A into B or any other class? With Guice, currently I am able to inject only same instance with all classes like below in guice container</p>
  
  <pre><code>bind(A.Class).toInstance(new A());
  new B(); // or create with other ways 
  </code></pre>