title: GWT/Gin Presenter instantiation
body: <p>I've implemented a GWT application following the recommendations of <a href="http://blog.hivedevelopment.co.uk/2009/08/google-web-toolkit-gwt-mvp-example.html" rel="nofollow">this tutorial</a>. I also downloaded the sample code, and I noticed that every Presenter of the demo needed to be injected in the main presenter constructor to be instantiated. The author included this in the source:</p>
  
  <pre><code>public class GreetingPresenter extends WidgetPresenter&lt;GreetingPresenter.Display&gt; {
  
      // FUDGE FACTOR!  Although this is not used, having GIN pass the object
      // to this class will force its instantiation and therefore will make the
      // response presenter listen for events (via bind()).  This is not a very good way to
      // achieve this, but I wanted to put something together quickly - sorry!
      private final GreetingResponsePresenter greetingResponsePresenter;
  
      @Inject
      public GreetingPresenter(final Display display, final EventBus eventBus, final DispatchAsync dispatcher, final GreetingResponsePresenter greetingResponsePresenter) {
              super(display, eventBus);       
              this.dispatcher = dispatcher;       
              this.greetingResponsePresenter = greetingResponsePresenter;     
              bind();
  }
  </code></pre>
  
  <p>I verified that if any Presenter doesn't get injected in GreetingPresenter, it won't be instantiated. For demonstration purposes this is cool because the whole app only has two Presenters, but in a Real-World application this can be a serious inconvenient.</p>
  
  <p>What's the proper way of accomplish Presenter instantiation?</p>
  
  <p><strong>EDIT:</strong> Including GIN related classes for reference:</p>
  
  <p><strong>Presenter module:</strong></p>
  
  <pre><code>public class GreetingClientModule extends AbstractPresenterModule {
  
      @Override
      protected void configure() {        
          bind(EventBus.class).to(DefaultEventBus.class).in(Singleton.class);
          bind(PlaceManager.class).in(Singleton.class);       
          bindPresenter(GreetingPresenter.class, GreetingPresenter.Display.class, GreetingView.class);
          bindPresenter(GreetingResponsePresenter.class, GreetingResponsePresenter.Display.class, GreetingResponseView.class);        
          bind(AppPresenter.class).in(Singleton.class);
          bind(CachingDispatchAsync.class);
      }
  }
  </code></pre>
  
  <p><strong>Ginjector:</strong></p>
  
  <pre><code>@GinModules({ ClientDispatchModule.class, GreetingClientModule.class })
  public interface GreetingGinjector extends Ginjector {
  
      AppPresenter getAppPresenter();
      PlaceManager getPlaceManager();
  
  }
  </code></pre>