title: Breaking cyclic dependency in Dagger
body: <p><em>I am very new to dagger--I don't even know yet if it will work for my application</em></p>
  
  <p>I have a search page that returns the latest news about a given celebrity.</p>
  
  <p>I have written a test to verify that results appear on the page when we search for a popular celebrity.</p>
  
  <p>The <code>page</code> has a <code>searchField</code>, which requires <code>page</code> in its constructor so the web driver I use for my tests can select it. </p>
  
  <p><strong>Celebrity Search Page Test</strong></p>
  
  <pre><code>public class CelebritySearchPageTest {
      @Test
      public void testSearchResultsForKevinBaconVerifyHisPopularity() {
          CelebritySearchPage searchPage = new CelebritySearchPage();
          searchPage.searchFor("Kevin Bacon");
          Assert.assertTrue(searchPage.getNumberOfResults() &gt; 9999999, "Verify that Kevin Bacon is still relevant");
      }
  }
  </code></pre>
  
  <p><strong>Celebrity Search Page</strong></p>
  
  <pre><code>public class CelebritySearchPage extends Page {
      @Inject
      @Named("search field")
      TextField searchField;
  
      public void searchFor(String text) {
          searchField.setText(text);
          // ...
      }
  
      public int getNumberOfResults() {
          // ...
      }
  }
  </code></pre>
  
  <p><strong>Celebrity Search Page Module</strong></p>
  
  <pre><code>@Module(injects = CelebritySearchPage.class)
  public class CelebritySearchPageModule {
      @Provides
      @Named("search field")
      public TextField provideSearchField() {
          return new TextField(/* How do I get the page? */, "#searchField");
      }
  }
  </code></pre>
  
  <p><strong>Page</strong></p>
  
  <pre><code>public abstract class Page {
      // ...
  }
  </code></pre>
  
  <p><strong>Text Field</strong></p>
  
  <pre><code>public class TextField {
      protected Page page;
      protected String selector;
  
      public TextField(Page page, String selector) {
          this.page = page;
          this.selector = selector;
      }
  
      public void setText(String text) {
          // ...
      }
  }
  </code></pre>
  
  <p>The problem is that <code>page</code> needs <code>searchField</code>, but <code>searchField</code> needs <code>page</code>. How do I get over this cyclic dependency?</p>
  
  <p><em>I can't initialize <code>searchField</code> inside of CelebritySearchPage</em></p>