This is a problem we've dealt with by using either assisted injection or a
setter method.
To use the former, the pattern is this:
// Some common marker interfaces
interface View { }
interface Presenter { }
// A common factory interface
interface ViewFactory<P extends Presenter, V extends View> {
V create(P presenter);
}
// You can also do this based on a subclass, etc
interface YourView extends View {
//...define its methods
interface YourViewFactory extends ViewFactory<YourPresenter, YourView> { }
}
class YourPresenter {
private final YourView view;
@Inject(YourViewFactory factory, ...) {
this.view = factory.create(this);
}
...
}
Depending on your abstraction needs, you can collapse / pull up the
interface definitions as you wish.
The most important thing here IMO is to keep the presenter free of GWT
logic, and as long as you do that, your unit testing of the presenter can
be done using plain testing code (i.e., no GWT testing code is necessary).
Some folks don't mind having the "presenter" variable non-final in the
view, and define a setter() method on the view:
class YourPresenter {
private final YourView view;
@Inject(YourView view, ...) {
this.view = view;
view.setPresenter(this);
}
...
}
There is more detail in this GWT issue, fwiw:
http://code.google.com/p/google-web-toolkit/issues/detail?id=6151
Fred
On Sat, Apr 28, 2012 at 2:21 PM, Adio <[email protected]> wrote:
> Hi every one, i am totally new to Guice - In DI frameworks in general
> - . Now i am facing a dilemma witch is how to bind and create with
> guice object that has dependency injection ? and here is what i mean
>
> @Inject
> public class A {
> private B b ;
>
> public A(B b){
> this.b=b;
> }
> }
>
> public class B {
>
> private A a ;
>
> @Inject
> public B(A a){
> this.a = a;
> }
>
>
> and here is a real situation of my problem, actually it is the MVP GWT
> pattern design using UiBinding.
>
> public class LoginPresenterImpl implements LoginPresenter {
>
> private HasHandlers eventBus;
> private LoginFormErrorMessages errorMessages;
> private UserAccountServiceAsync async;
> private LoginView loginDisplay;
>
> @Inject
> public LoginPresenterImpl(UserAccountServiceAsync serviceAsync,
> LoginView loginview, HasHandlers handlerManager,
> LoginFormErrorMessages loginFormErrorMessages) {
> async = serviceAsync;
> loginDisplay = loginview;
> eventBus = handlerManager;
> errorMessages = loginFormErrorMessages;
> }
>
> ......
>
> }
>
> and the LoginView is :
>
> public class LoginViewImpl extends Composite implements LoginView {
>
>
> @UiTemplate("LoginView.ui.xml")
> interface LoginViewUiBinder extends UiBinder<DecoratorPanel,
> LoginViewImpl> {
> }
>
> @UiField
> TextBox username;
> @UiField
> PasswordTextBox password;
> @UiField
> Button login;
> @UiField
> Button newRegistration;
> @UiField
> Label warningLabel;
>
>
> private LoginViewUiBinder binder =
> GWT.create(LoginViewUiBinder.class);
>
> @Inject
> private LoginPresenter loginPresenter;
>
>
> public LoginViewImpl() {
> initWidget(binder.createAndBindUi(this));
> }
> ......
>
> }
>
> how to binde the view ??? and the Presenter ?
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-guice?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.