GWT GIN circular dependency

939 views Asked by At

Here is an example that I have -

public class GinDemoPresenter implements Presenter {

   private View view;

   @Inject
   public GinDemoPresenter (View view) {
      this.view = view;
   }
   ....
}

public class GinDemoView implements View {

   private Presenter presenter;

   @Inject
   public GinDemoView(Presenter presenter) {
      this.presenter = presenter;
   }
   ....
}

During compilation I see this -

...
Cycle detected in the dependency graph.  Consider using a Provider?
...

Can someone provide an example of how to resolve circular dependency in GIN?

1

There are 1 answers

6
Christian Kuetbach On BEST ANSWER

The easiest way would be following pattern:

public class GinDemoPresenter implements Presenter {

   private View view;

   @Inject
   public GinDemoPresenter (View view) {
      this.view = view;
      view.setPresenter(this);
   }
   ....
}

public class GinDemoView implements View {

   private Presenter presenter;

   public GinDemoView() {
   }

   public void setPresenter(Presenter presenter){
      this.presenter = presenter;
   }
   ....
}

I would suggest to decouple the View from the Prensenter, by introducing interfaces.