Instantiate a PresenterWidget (GWTP) manually

只谈情不闲聊 提交于 2019-12-02 00:55:36
André

You can get the ClientGinjector reference and call a getYourPresenter() method. If it's declared as @Singleton it will return the same instance, if is not will create a new instance, same as using new, but injecting all parameters to the constructor. It will be the same as adding @Inject to a field.

Added: If you don't have the required presenter there, at your ClientGinjector, you can simply write a getter method at that interface. Ex:

public interface ClientGinjector extends Ginjector {
    ....
    SideMenuPresenter getSideMenuPresenter();
    ....
}
jdramaix

In GWTP 1.0 the Ginjector is not needed anymore (auto-generated by gwtp).

In your case (and each time you need multiple instance of a class) the best is to inject a Provider of your WidgetPresenter:

@Inject Provider<MyWidgetPresenter> myWidgetPresenterProvider; 

Each time you need a new instance of MyWidegetPresenter, call the get() method on the provider :

MyWidgetPresenter myWidgetPresenter = myWidgetPresenterProvider.get();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!