本文整理了Java中com.google.inject.util.Modules.override()
方法的一些代码示例,展示了Modules.override()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Modules.override()
方法的具体详情如下:
包路径:com.google.inject.util.Modules
类名称:Modules
方法名:override
[英]Returns a builder that creates a module that overlays override modules over the given modules. If a key is bound in both sets of modules, only the binding from the override modules is kept. If a single PrivateModule is supplied or all elements are from a single PrivateBinder, then this will overwrite the private bindings. Otherwise, private bindings will not be overwritten unless they are exposed. This can be used to replace the bindings of a production module with test bindings:
Module functionalTestModule
= Modules.override(getProductionModules()).with(getTestModules());
Prefer to write smaller modules that can be reused and tested without overrides.
[中]返回一个生成器,该生成器创建一个模块,该模块将覆盖给定模块上的模块。如果在两组模块中都绑定了密钥,则只保留来自覆盖模块的绑定。如果提供了单个PrivateModule,或者所有元素都来自单个PrivateBinder,那么这将覆盖私有绑定。否则,私有绑定将不会被覆盖,除非它们被公开。这可用于将生产模块的绑定替换为测试绑定:
Module functionalTestModule
= Modules.override(getProductionModules()).with(getTestModules());
更喜欢编写更小的模块,这些模块可以在没有覆盖的情况下重用和测试。
代码示例来源:origin: embulk/embulk
@Override
public List<Module> apply(List<Module> modules) {
Module override = new Module() {
public void configure(Binder binder) {
binder.bind(BulkLoader.class).to(TestingBulkLoader.class);
registerPluginTo(binder, InputPlugin.class, "preview_result", PreviewResultInputPlugin.class);
}
};
return ImmutableList.of(Modules.override(modules).with(ImmutableList.of(override)));
}
};
代码示例来源:origin: ben-manes/caffeine
@BeforeMethod
public void beforeMethod() {
Module module = Modules.override(new CacheAnnotationsModule()).with(new CaffeineJCacheModule());
Guice.createInjector(module).injectMembers(this);
}
代码示例来源:origin: apache/incubator-druid
private Injector newInjector(final Properties props)
{
List<Module> modules = ImmutableList.<Module>builder()
.addAll(GuiceInjectors.makeDefaultStartupModules())
.add(new LifecycleModule()).add(new CuratorModule()).build();
return Guice.createInjector(
Modules.override(modules).with(new Module()
{
@Override
public void configure(Binder binder)
{
binder.bind(Properties.class).toInstance(props);
}
})
);
}
代码示例来源:origin: kairosdb/kairosdb
mod = Modules.override(moduleList.get(0)).with(mod);
moduleList.set(0, mod);
代码示例来源:origin: Codecademy/EventHub
properties.putAll(System.getProperties());
Injector injector = Guice.createInjector(Modules.override(
new DmaIdListModule(),
new DatedEventIndexModule(),
代码示例来源:origin: bootique/bootique
private Module fold(RuntimeModule rm) {
RuntimeModule overriddenBy = rm.getOverriddenBy();
if (overriddenBy == null) {
trace(rm.getBqModule(), null);
return rm.getModule();
}
trace(rm.getBqModule(), overriddenBy.getBqModule());
// WARN: using recursion because fold.. is there a realistic prospect of this blowing the stack? I haven't
// seen overrides more than 2-4 levels deep.
// fold must happen in this order (overriding starts from the tail). Otherwise the algorithm will not work.
return Modules.override(rm.getModule()).with(fold(overriddenBy));
}
代码示例来源:origin: apache/incubator-druid
Module intermediateModules = Modules.override(defaultModules.getModules()).with(actualModules.getModules());
return Guice.createInjector(Modules.override(intermediateModules).with(extensionModules.getModules()));
代码示例来源:origin: HubSpot/Singularity
mainBinder.install(Modules.override(new SingularityMainModule(configuration))
.with(new Module() {
mainBinder.install(Modules.override(new SingularityMesosModule())
.with(new Module() {
代码示例来源:origin: org.eclipse.xtext/org.eclipse.xtext.util
public static Module mixin(Module...m) {
if (m.length==0)
return null;
Module current = m[0];
for (int i=1;i<m.length;i++) {
current = Modules.override(current).with(m[i]);
}
return current;
}
}
代码示例来源:origin: co.cask.cdap/cdap-data-fabric
public Module getDataFabricModule(final TransactionManager transactionManager) {
return Modules.override(new DataFabricLocalModule()).with(new AbstractModule() {
@Override
protected void configure() {
// InMemorySystemTxClient uses TransactionManager directly, so we need to share TransactionManager.
bind(TransactionManager.class).toInstance(transactionManager);
}
});
}
代码示例来源:origin: org.eclipse.vorto/org.eclipse.vorto.editor.infomodel.web
@Override
public Injector createInjector() {
final InformationModelRuntimeModule runtimeModule = new InformationModelRuntimeModule();
final InformationModelWebModule webModule = new InformationModelWebModule(this.executorServiceProvider);
Modules.OverriddenModuleBuilder _override = Modules.override(runtimeModule);
Module _with = _override.with(webModule);
return Guice.createInjector(_with);
}
代码示例来源:origin: caelum/vraptor
public void start(ServletContext context) {
this.context = context;
APPLICATION.start();
container = new GuiceContainer();
injector = Guice.createInjector(Stage.PRODUCTION, Modules.override(new VRaptorAbstractModule(context, container)).with(customModule()));
executeStereotypeHandlers();
injector.injectMembers(REQUEST);
injector.injectMembers(SESSION);
}
代码示例来源:origin: org.spincast/spincast-plugins-jdbc
@Override
public Module apply(Module module) {
Module pluginModule = getPluginModule();
setContextTypes(pluginModule);
module = Modules.override(module).with(pluginModule);
return module;
}
代码示例来源:origin: org.testeditor.web/org.testeditor.web.dropwizard.testing
/**
* Inspired by org.eclipse.xtext.util.Modules2
*/
protected static com.google.inject.Module mixin(final com.google.inject.Module... modules) {
final com.google.inject.Module seed = Modules.EMPTY_MODULE;
final Function2<com.google.inject.Module, com.google.inject.Module, com.google.inject.Module> _function = (com.google.inject.Module current, com.google.inject.Module module) -> {
return Modules.override(current).with(module);
};
return IterableExtensions.<com.google.inject.Module, com.google.inject.Module>fold(((Iterable<com.google.inject.Module>)Conversions.doWrapArray(modules)), seed, _function);
}
}
代码示例来源:origin: org.spincast/spincast-plugins-flyway-utils
@Override
public Module apply(Module module) {
//==========================================
// We make sure all the non-default plugins
// we depend on are applied...
//==========================================
module = applyRequiredPlugins(module);
Module pluginModule = getPluginModule();
setContextTypes(pluginModule);
module = Modules.override(module).with(pluginModule);
return module;
}
代码示例来源:origin: org.wso2.org.apache.shindig/shindig-gadgets
private Module getParseModule() {
return Modules.override(new ParseModule()).with(new AbstractModule() {
@Override
protected void configure() {
bind(GadgetHtmlParser.class).to(getParserClass());
}
});
}
代码示例来源:origin: com.lmco.shindig/shindig-gadgets
private Module getParseModule() {
return Modules.override(new ParseModule()).with(new AbstractModule() {
@Override
protected void configure() {
bind(GadgetHtmlParser.class).to(getParserClass());
}
});
}
代码示例来源:origin: locationtech/geogig
static Context createContext(File repositoryDirectory) {
Platform platform = new TestPlatform(repositoryDirectory);
URI uri = repositoryDirectory.getAbsoluteFile().toURI();
Hints hints = new Hints().uri(uri).platform(platform);
return Guice.createInjector(Modules.override(new GeogigModule())
.with(new HintsModule(hints), new RocksStorageModule())).getInstance(Context.class);
}
代码示例来源:origin: org.geogit/geogit-core
@Before
public void setUp() {
File workingDirectory = tempFolder.newFolder("mockWorkingDir");
Platform testPlatform = new TestPlatform(workingDirectory);
Injector injector = Guice.createInjector(Modules.override(new GeogitModule()).with(
new MemoryModule(testPlatform)));
fakeGeogit = new GeoGIT(injector);
assertNotNull(fakeGeogit.getOrCreateRepository());
command = fakeGeogit.command(DiffTree.class);
}
代码示例来源:origin: locationtech/geogig
public @Before void setUp() throws Exception {
File workingDirectory = tempFolder.newFolder("mockWorkingDir");
Platform testPlatform = new TestPlatform(workingDirectory);
Context injector = Guice
.createInjector(Modules.override(new GeogigModule()).with(new MemoryModule(),
new HintsModule(new Hints().platform(testPlatform))))
.getInstance(Context.class);
GeoGIG geogig = new GeoGIG(injector);
repo = geogig.getOrCreateRepository();
command = repo.command(FindChangedTrees.class);
ftproto = DataUtilities.createType("points", "sp:String,ip:Integer,pp:Point:srid=3857");
}
内容来源于网络,如有侵权,请联系作者删除!