GWT GIN循环依赖

时间:2013-12-06 19:23:35

标签: gwt gin

这是我的一个例子 -

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;
   }
   ....
}

在编译期间,我看到了这个 -

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

有人可以提供一个如何在GIN中解决循环依赖的示例吗?

1 个答案:

答案 0 :(得分:3)

最简单的方法是遵循模式:

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;
   }
   ....
}

我建议通过引入接口将ViewPrensenter分离。