title: What is the use of requireBinding?
body: <p>I am relatively new to Guice and trying to understand the usage of requireBinding and when/why to use it.</p>
  
  <p>As per my understanding, while creating an injector Guice goes through the code of configure() method of all the modules and builds a dependency graph.</p>
  
  <p>If Guice builds the dependency graph in itself then why does a module need to add a requireBinding? As long as I could understand the usage of requireBinding is to add an explicit dependency on a class which guice's dependency graph seems to be doing anyway.</p>
  
  <p>I would like to understand that when should we use requireBinding and what is the impact of not using it in a module.</p>
  
  <p>I have read Guice's official documentation and search on all the existing questions on Stackoverflow/any other blog but couldn't find a satisfying answer to the above question.</p>
  
  <p><strong>Adding to the original question.</strong></p>
  
  <p>Looking at the Source code of the AbstractModule the implementation looks like</p>
  
  <pre><code>protected void requireBinding(Key&lt;?&gt; key) {
      this.binder().getProvider(key);
  }
  
  protected void requireBinding(Class&lt;?&gt; type) {
      this.binder().getProvider(type);
  }
  </code></pre>
  
  <p>Which you would assume will not have any side effect as it's a "get" call.
  But on the other hand looking it the binder itself it adds some element to a list of elements of type <strong>ProviderLookup</strong></p>
  
  <pre><code>public &lt;T&gt; Provider&lt;T&gt; getProvider(Dependency&lt;T&gt; dependency) {
          ProviderLookup&lt;T&gt; element = new ProviderLookup(this.getElementSource(), dependency);
          this.elements.add(element);
          return element.getProvider();
      }
  </code></pre>