gpt4 book ai didi

GWT GIN 循环依赖

转载 作者:行者123 更新时间:2023-12-04 04:32:07 30 4
gpt4 key购买 nike

这是我的一个例子 -

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 中的循环依赖的例子吗?

最佳答案

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

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

我建议解耦 View来自 Prensenter ,通过引入接口(interface)。

关于GWT GIN 循环依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20431943/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com