title: Call methods from Guice module?
body: <p>So I need to work on a Guice project that I inherited from a developer who worked on it earlier, and I have a specific problem to address.
  Let me briefly introduce the application design.</p>
  
  <p><strong>MyService.java</strong></p>
  
  <pre><code>public static void main(String[] args) {
  
      Injector injector = createInjector(new MyModule());
  }
  </code></pre>
  
  <p><strong>MyModule.java</strong></p>
  
  <pre><code>// ...
  
  @Inject
  @Provides
  @Singleton
  public Client getClient(@Named("config") String config) {
      // Client should be singleton
      return new Client(config); 
  } 
  </code></pre>
  
  <p>And now is the problem that I have to write the service operation that uses the <code>Client</code> which exists as a singleton somewhere in the application, but I don't know what would be the good way to obtain it. I need something like the following.</p>
  
  <p><strong>ServiceOperations.java</strong> </p>
  
  <pre><code>// ...
  
  public String getData() {
      // somehow obtain that client - how?
      // and then call operations on the client
      return client.getData();
  }
  </code></pre>
  
  <p>If it wasn't Guice, I would just have a <code>ClientFactory</code>, and call something like <code>ClientFactory.getClientInstance()</code> from my <code>getData()</code> method and have the client reference, but with Guice, what is the proper way to obtain it?</p>
  
  <p>PS. I am just learning Guice. Thanks!</p>