title: dynamic binding with dagger 2
body: <p>I have problems migrating my Android app from <code>Dagger</code> to <code>Dagger2</code>.</p>
  
  <p>I use Dagger to inject mocks at different layers during testing (unit , functional device and everything in between).</p>
  
  <p>E.g. I have a <code>NetworkingModule</code> which provides a <code>HttpTransport</code> and a <code>ServerConnector</code>. For some test I just mock the http layer, for others I mock the <code>ServerConnector</code>, and other test use release classes to test integration with a real test server.</p>
  
  <p>These test can be run on all build flavors (debug, release, ...).</p>
  
  <p>I found only descriptions of <code>Dagger2</code> which set a single static injection configuration per build type - i.e. a release component to bind real classes and a debug component to bind one set of mocks.</p>
  
  <p>I need to find a way to have the test cases replace modules in the application start up phase.</p>
  
  <p>How can I achieve this? In my thoughts I always get stuck when the application triggers the building of the graph for which it has to use a Component which is the implementation of a certain interface which has static annotation of its modules???</p>
  
  <p>To ask differently: Is it possible to compile multiple modules in the same build which provide the same injections? How would I then inject with the right module at run time?</p>
  
  <p>Can someone please draft me a solution for my example of the <code>NetworkingModule</code>.</p>
  
  <p>BTW: I make heavy use of <code>Espresso</code>, <code>Robolectric</code>, and <code>Mockito</code>.</p>
  
  <p>Thx.</p>