开发者

Gwt-dispatch injection

开发者 https://www.devze.com 2023-01-06 03:34 出处:网络
To use gwt-dispatch we create an object 开发者_开发问答like: private static final DispatchAsync dispatchAsync = GWT.create(DefaultDispatchAsync.class);

To use gwt-dispatch we create an object 开发者_开发问答like:

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

Is there any way to do this with injection, I mean how to inject this DispatchAsync object into other classes where we need to use it.

This is something related to @Inject annotation!


Yes, you can use Gin to inject your dispatch interface using the @Inject annotation.

First you need to configure a Gin binding for the DispatchAsync interface to an implementation in your Gin ClientModule.

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

Once this is done, you can have Gin inject the dispatcher in your constructors.

class foo {
    private final DispatchAsync dispatcher;

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

精彩评论

暂无评论...
验证码 换一张
取 消