如何在GIN中覆盖绑定 [英] How to override binding in GIN

查看:76
本文介绍了如何在GIN中覆盖绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了Guice的答案覆盖Guice中的绑定,但不知道如何在GWT.

I find the answer for Guice Overriding Binding in Guice but don't know how to do the same for GIN in GWT.

提前谢谢!

推荐答案

据我所知,它不受支持.

As far as I know, it's not supported.

回答您的评论:

如果您正在运行纯" JUnit测试(而不是GWTTestcases),则不使用GIN,而是使用Guice,并且在Guice中可以覆盖模块.如果要重用GIN模块,请使用GinModuleAdapter包装它们.因此,您可以执行以下操作:

If you're running "pure" JUnit tests (not GWTTestcases) you don't use GIN, you use Guice, and in Guice you can override modules. If you want to reuse GIN modules, then wrap them using GinModuleAdapter. So you can do something like this:

static class MyGinModule extends GinModule {
  ...
}
static class MyGuiceModule extends AbstractModule {
  ...
}

// And somewhere in your code, here's how you could create the Injector
Module myWrappedGinModule = new GinModuleAdapter(new MyGinModule());
Module myModule = Modules.override(myWrappedGinModule).with(new MyGuiceModule());
Injector injector = Guice.createInjector(myModule);

这篇关于如何在GIN中覆盖绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆