Gwt-dispatch injection

To use gwt-dispatch, we create an object like:

private static final DispatchAsync dispatchAsync = GWT.create(DefaultDispatchAsync.class);

Is there a way to do this with an injection, I mean, how to embed this object DispatchAsyncin other classes, where we need to use it.

This is due to the annotation @Inject!

+3
source share
1 answer

Yes, you can use Gin to enter the submit interface using the @Inject annotation.

First you need to configure the Gin binding for the DispatchAsync interface to implement in your Gin ClientModule.

bind(DispatchAsync.class).to(DefaultDispatchAsync.class).in(Singleton.class);

Once this is done, you can force Gin to inject a dispatcher into your constructors.

class foo {
    private final DispatchAsync dispatcher;

    @Inject
    public foo(final DispatchAsync dispacher) {
        this.dispatcher = dispatcher;
    }
}
+7
source

Source: https://habr.com/ru/post/1753473/


All Articles