本文整理汇总了Java中com.google.inject.util.Modules.combine方法的典型用法代码示例。如果您正苦于以下问题:Java Modules.combine方法的具体用法?Java Modules.combine怎么用?Java Modules.combine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.inject.util.Modules
的用法示例。
在下文中一共展示了Modules.combine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testModuleWithWorkQueue
import com.google.inject.util.Modules; //导入方法依赖的package包/类
/**
* Creates a module that will prepare a private in-memory database, using a specific task store
* implementation bound within the key factory and provided module.
*
* @param keyFactory Key factory to use.
* @param taskStoreModule Module providing task store bindings.
* @return A new database module for testing.
*/
@VisibleForTesting
public static Module testModuleWithWorkQueue(
KeyFactory keyFactory,
Optional<Module> taskStoreModule) {
return Modules.combine(
new AbstractModule() {
@Override
protected void configure() {
bind(GatedWorkQueue.class).annotatedWith(AsyncExecutor.class).toInstance(
new GatedWorkQueue() {
@Override
public <T, E extends Exception> T closeDuring(
GatedOperation<T, E> operation) throws E {
return operation.doWithGateClosed();
}
});
}
},
testModule(keyFactory, taskStoreModule)
);
}
示例2: getChildServletModule
import com.google.inject.util.Modules; //导入方法依赖的package包/类
@Override
protected Module getChildServletModule() {
return Modules.combine(
new ApiModule(),
new H2ConsoleModule(true),
new HttpSecurityModule(
new IniShiroRealmModule(ini),
Key.get(Filter.class, SHIRO_AFTER_AUTH_FILTER_ANNOTATION)),
new AbstractModule() {
@Override
protected void configure() {
bind(Filter.class)
.annotatedWith(SHIRO_AFTER_AUTH_FILTER_ANNOTATION)
.toInstance(shiroAfterAuthFilter);
MockDecoratedThrift.bindForwardedMock(binder(), auroraAdmin);
}
});
}
示例3: getRootModule
import com.google.inject.util.Modules; //导入方法依赖的package包/类
public static Module getRootModule(final String webinfRoot) {
return Modules.combine(
Modules.combine(extraModules),
new WalkaroundServerModule(),
new ConvStoreModule(),
new UdwStoreModule(),
new AbstractModule() {
@Override public void configure() {
bind(String.class).annotatedWith(Names.named("webinf root")).toInstance(webinfRoot);
// TODO(ohler): Find a way to create these bindings in StoreModuleHelper; but note that
// http://code.google.com/p/google-guice/wiki/Multibindings says something about
// private modules not interacting well with multibindings. I don't know if that
// refers to our situation here.
MapBinder<String, SlobFacilities> mapBinder =
MapBinder.newMapBinder(binder(), String.class, SlobFacilities.class);
for (Entry<String, Class<? extends Annotation>> entry
: ImmutableMap.of(ConvStoreModule.ROOT_ENTITY_KIND, ConvStore.class,
UdwStoreModule.ROOT_ENTITY_KIND, UdwStore.class).entrySet()) {
mapBinder.addBinding(entry.getKey())
.to(Key.get(SlobFacilities.class, entry.getValue()));
}
}
});
}
示例4: newConfigModule
import com.google.inject.util.Modules; //导入方法依赖的package包/类
@Override
public Module newConfigModule() {
return Modules.combine(
new AbstractModule() {
@Override
protected void configure() {
bind(FilterBindings.class)
.toInstance(new FilterBindings(
new BindingRepository<>(),
new BindingRepository<>()));
bind(ServerConfig.class)
.toInstance(new ServerConfig(new ServerConfig.Builder()));
bind(ServletPathsConfig.class)
.toInstance(new ServletPathsConfig(new ServletPathsConfig.Builder()));
}
},
new ConnectorFactoryRegistryModule());
}
示例5: newFilterModule
import com.google.inject.util.Modules; //导入方法依赖的package包/类
private static com.google.inject.Module newFilterModule(
final BindingRepository<RequestFilter> requestFilters,
final BindingRepository<ResponseFilter> responseFilters) {
return Modules.combine(
new AbstractModule() {
@Override
protected void configure() {
bind(FilterBindings.class).toInstance(
new FilterBindings(
requestFilters != null ? requestFilters : EMPTY_REQUEST_FILTER_REPOSITORY,
responseFilters != null ? responseFilters : EMPTY_RESPONSE_FILTER_REPOSITORY));
bind(ServerConfig.class).toInstance(new ServerConfig(new ServerConfig.Builder()));
bind(ConnectorConfig.class).toInstance(new ConnectorConfig(new ConnectorConfig.Builder()));
bind(ServletPathsConfig.class).toInstance(new ServletPathsConfig(new ServletPathsConfig.Builder()));
}
},
new ConnectorFactoryRegistryModule());
}
示例6: newConfigModule
import com.google.inject.util.Modules; //导入方法依赖的package包/类
private static Module newConfigModule(
final ServerConfig.Builder serverConfig,
final ConnectorConfig.Builder connectorConfigBuilder,
final Module... guiceModules) {
return Modules.combine(
new AbstractModule() {
@Override
protected void configure() {
bind(ServletPathsConfig.class).toInstance(new ServletPathsConfig(new ServletPathsConfig.Builder()));
bind(ServerConfig.class).toInstance(new ServerConfig(serverConfig));
bind(ConnectorConfig.class).toInstance(new ConnectorConfig(connectorConfigBuilder));
bind(FilterBindings.class).toInstance(
new FilterBindings(
new BindingRepository<RequestFilter>(),
new BindingRepository<ResponseFilter>()));
}
},
new ConnectorFactoryRegistryModule(connectorConfigBuilder),
new ServletModule(),
Modules.combine(guiceModules));
}
示例7: testCombineSources
import com.google.inject.util.Modules; //导入方法依赖的package包/类
/** The module returned by Modules.combine shouldn't show up in binder sources. */
public void testCombineSources() {
final Module m1 = newModule(1);
final Module m2 = newModule(2L);
final Module combined1 = Modules.combine(m1, m2);
Module skipSourcesModule =
new AbstractModule() {
@Override
protected void configure() {
install(combined1);
}
};
final Module combined2 = Modules.combine(skipSourcesModule);
Injector injector = Guice.createInjector(combined2);
ElementSource source = (ElementSource) injector.getBinding(Integer.class).getSource();
assertEquals(4, source.getModuleClassNames().size());
assertEquals(
ImmutableList.of(
m1.getClass().getName(),
combined1.getClass().getName(),
skipSourcesModule.getClass().getName(),
combined2.getClass().getName()),
source.getModuleClassNames());
StackTraceElement stackTraceElement = (StackTraceElement) source.getDeclaringSource();
assertEquals(skipSourcesModule.getClass().getName(), stackTraceElement.getClassName());
}
示例8: testCombineSources
import com.google.inject.util.Modules; //导入方法依赖的package包/类
/**
* The module returned by Modules.combine shouldn't show up in binder sources.
*/
public void testCombineSources() {
final Module m1 = newModule(1);
final Module m2 = newModule(2L);
final Module combined1 = Modules.combine(m1, m2);
Module skipSourcesModule = new AbstractModule() {
@Override protected void configure() {
install(combined1);
}
};
final Module combined2 = Modules.combine(skipSourcesModule);
Injector injector = Guice.createInjector(combined2);
ElementSource source = (ElementSource) injector.getBinding(Integer.class).getSource();
assertEquals(source.getModuleClassNames().size(), 4);
assertEquals(ImmutableList.of(m1.getClass().getName(),
combined1.getClass().getName(), skipSourcesModule.getClass().getName(),
combined2.getClass().getName()), source.getModuleClassNames());
StackTraceElement stackTraceElement = (StackTraceElement) source.getDeclaringSource();
assertEquals(skipSourcesModule.getClass().getName(), stackTraceElement.getClassName());
}
示例9: loadFromClasspath
import com.google.inject.util.Modules; //导入方法依赖的package包/类
public static Module loadFromClasspath(Site site, Class<? extends Module> moduleType) {
List<Module> runtime = new LinkedList<Module>();
List overrides = new LinkedList();
runtime.add(new DefaultSiteModule(site));
for (Module module : ServiceLoader.load(moduleType, site.getClassLoader())) {
ClassUtils.apply(module, site);
if (module.getClass().isAnnotationPresent(OverrideModule.class)) {
overrides.add(module);
} else {
runtime.add(module);
}
}
return overrides.isEmpty() ? Modules.combine(runtime) : Modules.override(runtime).with(overrides);
}
示例10: onCreate
import com.google.inject.util.Modules; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
Module defaultModule = RoboGuice.newDefaultRoboModule(this);
Module dbInspectorModule = new DBInspectorModule();
Module combinedModule = Modules.combine(defaultModule, dbInspectorModule);
Injector injector = RoboGuice.setBaseApplicationInjector(this, RoboGuice.DEFAULT_STAGE, combinedModule);
Map<Key<?>, Binding<?>> bindings = injector.getAllBindings();
for (Key<?> key : bindings.keySet()) {
Binding<?> value = bindings.get(key);
Ln.d("binding key '" + key + "', value '" + value + "'");
}
Ln.i("Application initialized.");
}
示例11: getRuntimeModule
import com.google.inject.util.Modules; //导入方法依赖的package包/类
private static Module getRuntimeModule(String transport, String host, int port, Properties joynrConfig) {
Module runtimeModule;
if (transport != null) {
if (transport.contains("websocketcc")) {
configureWebSocket(host, port, joynrConfig);
runtimeModule = new CCWebSocketRuntimeModule();
} else if (transport.contains("websocket")) {
configureWebSocket(host, port, joynrConfig);
runtimeModule = new LibjoynrWebSocketRuntimeModule();
} else {
runtimeModule = new CCInProcessRuntimeModule();
}
Module backendTransportModules = Modules.EMPTY_MODULE;
if (transport.contains("http")) {
backendTransportModules = Modules.combine(backendTransportModules, new AtmosphereMessagingModule());
}
if (transport.contains("mqtt")) {
configureMqtt(joynrConfig);
backendTransportModules = Modules.combine(backendTransportModules, new MqttPahoModule());
}
return Modules.override(runtimeModule).with(backendTransportModules);
}
return Modules.override(new CCInProcessRuntimeModule()).with(new MqttPahoModule());
}
示例12: initInjection
import com.google.inject.util.Modules; //导入方法依赖的package包/类
/** Creates the injector for the test and injects all fields with the initialized injector. */
private void initInjection(Properties properties) {
// STEP 1: set up language N4JS
// the following is doing roughly the same as N4JSStandaloneSetup.doSetup(), but is using a custom-built
// Guice module for injector creation:
TypesPackage.eINSTANCE.getNsURI();
TypeRefsPackage.eINSTANCE.getNsURI();
N4JSPackage.eINSTANCE.getNsURI();
N4mfPackage.eINSTANCE.getNsURI();
XMLTypePackage.eINSTANCE.getNsURI();
// combine all modules for N4JSC
final Module combinedModule = Modules.combine(new N4JSRuntimeModule(), new TesterModule(),
new N4JSHeadlessGeneratorModule(properties));
// override with customized bindings
final Module overridenModule = Modules.override(combinedModule).with(binder -> {
binder.bind(TestTreeTransformer.class)
.to(CliTestTreeTransformer.class);
binder.bind(IHeadlessLogger.class)
.toInstance(new ConfigurableHeadlessLogger(verbose, debug));
});
RegularExpressionStandaloneSetup.doSetup();
TypesStandaloneSetup.doSetup();
N4MFStandaloneSetup.doSetup();
TypeExpressionsStandaloneSetup.doSetup();
final Injector injector = Guice.createInjector(overridenModule);
new N4JSStandaloneSetup().register(injector);
injector.injectMembers(this);
}
示例13: module
import com.google.inject.util.Modules; //导入方法依赖的package包/类
public static Module module(final Named name)
{
return Modules.combine(
new AbstractModule()
{
@Override
protected void configure()
{
// ConfigSystem.configModule() creates a module with a lot of bindings that need to be non-private.
// make sure you don't specify this within the PrivateModule.
install(ConfigSystem.configModule(ProviderExample.Config.class, name));
}
},
new PrivateModule()
{
@Override
protected void configure()
{
// NOTE: MUST explicitly bind and expose this class within the private module for Guice to be able
// to use the alias binding below during injection of this class.
bind(ProviderExample.class).annotatedWith(name).to(ProviderExample.class);
expose(Key.get(ProviderExample.class, name));
// alias binding; only applies to other bind() or install() methods in this private module. Do not expose this.
// This allows us to @Inject a Config instance into this class w/o knowing the bound name in advance.
bind(Config.class).to(Key.get(Config.class, name));
// Binding for the class being provided by the provider
bind(ProviderExample.Foo.class)
.annotatedWith(name)
.toProvider(Key.get(ProviderExample.class, name))
.in(Scopes.SINGLETON);
expose(Key.get(ProviderExample.Foo.class, name));
}
});
}
示例14: getUniversalModule
import com.google.inject.util.Modules; //导入方法依赖的package包/类
@VisibleForTesting
static Module getUniversalModule() {
return Modules.combine(
new LifecycleModule(),
new StatsModule(),
new AppModule(),
new CronModule(),
new DbModule.MigrationManagerModule(),
DbModule.productionModule(Bindings.annotatedKeyFactory(Storage.Volatile.class)),
new DbModule.GarbageCollectorModule());
}
示例15: getChildServletModule
import com.google.inject.util.Modules; //导入方法依赖的package包/类
@Override
protected Module getChildServletModule() {
return Modules.combine(
new ApiModule(),
new AbstractModule() {
@Override
protected void configure() {
bind(AnnotatedAuroraAdmin.class).toInstance(thrift);
}
});
}