title: Should Guice Providers with expensive member instances as be annotated with @Singleton?
body: <p>Should <strong>Guice Providers</strong> be annotated with <code>@Singleton</code>? My justification: if the Provider is providing an object to other Singleton classes and the object itself is relatively expensive to create, then wouldn't it make sense to use a Singleton Provider that constructs the expensive object in its <code>@Inject</code>-marked constructor, store it as a member and just return that already-saved global variable in the getter? Something like this:</p>
  
  <pre><code>@Singleton
  public class MyProvider extends Provider&lt;ExpensiveObject&gt; {
      private ExpensiveObject obj;
  
      @Inject
      public MyProvider() {
          /* Create the expensive object here, set it to this.obj */
      }
  
      @Override
      public ExpensiveObject get() {
          return obj;
      }
  }
  </code></pre>
  
  <p><hr></p>
  
  <h2>Update</h2>
  
  <p>Let me clarify a little bit more here. This is not about whether I should be using <code>@Singleton</code> or <code>.in(Singleton.class)</code>. This has to do more with the "caching" of the created object.</p>
  
  <p>Let's say that object creation required multiple RPCs to complete, such as deserializing JSON or making HTTP requests. This could take quite some time. If I am going to use this Provider to inject into classes multiple times, then doesn't it make sense to only create such an object once?</p>
  
  <p>Also note that I must be able to use a Provider because I need to be able to inject into the Provider.</p>