本文整理汇总了Java中com.google.inject.Guice.createInjector方法的典型用法代码示例。如果您正苦于以下问题:Java Guice.createInjector方法的具体用法?Java Guice.createInjector怎么用?Java Guice.createInjector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.inject.Guice
的用法示例。
在下文中一共展示了Guice.createInjector方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testExposed
import com.google.inject.Guice; //导入方法依赖的package包/类
@Test
public void testExposed() {
final Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
DuplexBinder.create(this.binder()).install(new DuplexModule() {
@Override
protected void configure() {
this.bindAndExpose(Thing.class).to(ThingA.class);
this.bindAndExpose(Thing.class).annotatedWith(ThingAnnotation.class).to(ThingB.class);
}
});
}
});
final ExposeThings things = injector.getInstance(ExposeThings.class);
assertEquals(ThingA.class, things.a.getClass());
assertEquals(ThingB.class, things.b.getClass());
}
示例2: testSingletonBoundScopeProvider
import com.google.inject.Guice; //导入方法依赖的package包/类
@Test
public void testSingletonBoundScopeProvider() {
final Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
this.bindScope(LazySingleton.class, LazySingleton.SCOPE);
}
});
assertEquals(AnnotatedSingletonThing.CONSTRUCTION_COUNT.get(), 0);
final AnnotatedSingletonThingProvider provider = injector.getInstance(AnnotatedSingletonThingProvider.class);
assertEquals(AnnotatedSingletonThing.CONSTRUCTION_COUNT.get(), 0);
final AnnotatedSingletonThing ap = provider.provider.get();
assertEquals(AnnotatedSingletonThing.CONSTRUCTION_COUNT.get(), 1);
final AnnotatedSingletonThing bp = provider.provider.get();
assertEquals(AnnotatedSingletonThing.CONSTRUCTION_COUNT.get(), 1);
assertSame(ap, bp);
}
示例3: setup
import com.google.inject.Guice; //导入方法依赖的package包/类
@Before
public void setup() {
Injector injector = Guice.createInjector(new ModuleIT());
accessController = (PropertiesBasedAccessController) injector.getInstance(AccessController.class);
clusterManager = injector.getInstance(ClusterManager.class);
objectManager = injector.getInstance(ObjectManager.class);
factManager = injector.getInstance(FactManager.class);
clientFactory = injector.getInstance(ClientFactory.class);
factSearchManager = injector.getInstance(FactSearchManager.class);
apiServer = injector.getInstance(ApiServer.class);
// Start up everything in correct order.
accessController.startComponent();
clusterManager.startComponent();
objectManager.startComponent();
factManager.startComponent();
clientFactory.startComponent();
factSearchManager.startComponent();
apiServer.startComponent();
}
示例4: ifCommmandIsInvalidResponseExceptionIsThrown
import com.google.inject.Guice; //导入方法依赖的package包/类
@Test
public void ifCommmandIsInvalidResponseExceptionIsThrown() throws IOException, URISyntaxException {
String command = "invalid";
Map<String, Object> opts = new HashMap<>();
opts.put(BROWSER, CHROME);
opts.put(DRIVER, chromedriverFile.getAbsolutePath());
opts.put(APPLICATION, configurationFile.getAbsolutePath());
opts.put(URL, localhostUrl);
opts.put(CASE, caseFile.getAbsolutePath());
opts.put(SCREEN, screenString);
opts.put(TIMEOUT, timeoutString);
opts.put(PRECISION, precisionString);
Module module = new DefaultModule(command, opts);
Injector injector = Guice.createInjector(module);
try {
IOProvider<ResponseFilter> instance = injector.getInstance(new Key<IOProvider<ResponseFilter>>() {});
instance.get();
} catch (ProvisionException e) {
assertTrue(e.getCause() instanceof NoSuchCommandException);
}
}
示例5: test_interceptor
import com.google.inject.Guice; //导入方法依赖的package包/类
@Test
public void test_interceptor() throws ClassNotFoundException {
Injector injector = Guice.createInjector((Module) binder -> binder.bindInterceptor(
Matchers.identicalTo(TestedRpcHandler.class),
Matchers.any(),
new RpcHandlerMethodInterceptor()
));
TestedRpcHandler methodHandler
= injector.getInstance(TestedRpcHandler.class);
methodHandler.handleRequest(RpcEnvelope.Request.newBuilder().build(), new OrangeContext());
SameGuiceModuleAssertionOnInterceptorInvokation sameGuiceModuleAssertionOnInterceptorInvokation
= injector.getInstance(SameGuiceModuleAssertionOnInterceptorInvokation.class);
sameGuiceModuleAssertionOnInterceptorInvokation.test_that_intercepted_rpc_handler_still_verified();
assertThat(ReflectionUtil.findSubClassParameterType(methodHandler, 0)).
isEqualTo(RpcEnvelope.Request.class);
assertThat(ReflectionUtil.findSubClassParameterType(methodHandler, 1)).
isEqualTo(RpcEnvelope.Response.class);
}
示例6: setStateInputTest
import com.google.inject.Guice; //导入方法依赖的package包/类
@Test
public void setStateInputTest() throws ApiException, IOException, URISyntaxException {
Injector injector = Guice.createInjector(new AbstractModule() {
protected void configure() {
bind(InputPortsApi.class).toInstance(inputPortsApiMock);
bind(OutputPortsApi.class).toInstance(outputPortsApiMock);
bind(Integer.class).annotatedWith(Names.named("timeout")).toInstance(1);
bind(Integer.class).annotatedWith(Names.named("interval")).toInstance(1);
bind(Boolean.class).annotatedWith(Names.named("forceMode")).toInstance(false);
}
});
PortService portService = injector.getInstance(PortService.class);
PortEntity portStopped = new PortEntity();
portStopped.setComponent(new PortDTO());
portStopped.getComponent().setName("name");
portStopped.getComponent().setId("id");
portStopped.getComponent().setState(PortDTO.StateEnum.STOPPED);
when(inputPortsApiMock.updateInputPort(eq("id"),any())).thenReturn(portStopped);
PortEntity port = new PortEntity();
port.setId("id");
port.setComponent(new PortDTO());
port.getComponent().setId("id");
port.getComponent().setState(PortDTO.StateEnum.RUNNING);
port.getComponent().setType(PortDTO.TypeEnum.INPUT_PORT);
portService.setState(port, PortDTO.StateEnum.STOPPED);
verify(inputPortsApiMock, times(1)).updateInputPort(eq("id"), any());
}
示例7: getInjector
import com.google.inject.Guice; //导入方法依赖的package包/类
@Override
protected Injector getInjector() {
Injector injector = Guice.createInjector(
Stage.PRODUCTION,
new JerseyGuiceModule("__HK2_Generated_0"),
new ServletModule(),
new AppModule()
);
JerseyGuiceUtils.install(injector);
return injector;
}
示例8: build
import com.google.inject.Guice; //导入方法依赖的package包/类
public RaftService build(StateMachine stateMachine) {
RaftModule raftModule = new RaftModule(local, members, logDir, stateMachine);
raftModule.setTimeout(timeout);
if (eventLoop.isPresent()) {
raftModule.setNioEventLoop(eventLoop.get());
}
Injector injector = Guice.createInjector(raftModule);
return injector.getInstance(RaftService.class);
}
示例9: main
import com.google.inject.Guice; //导入方法依赖的package包/类
public static void main(String[] args, DistillerModuleFactory moduleFactory) throws IOException {
Config config = Config.of(args);
config.dump();
DistillerModule module = moduleFactory.create(config);
Injector injector = Guice.createInjector(module);
LoggerLevelAccessor loggerLevelAccessor = injector.getInstance(LoggerLevelAccessor.class);
LoggerLevels.applyLoggerLevelSpecs(config.getLoggerLevelSpecs(), loggerLevelAccessor);
Distiller distiller = injector.getInstance(Distiller.class);
try {
distiller.run();
} finally {
distiller.close();
}
}
示例10: injectWithGuice
import com.google.inject.Guice; //导入方法依赖的package包/类
@Test
void injectWithGuice() {
Injector injector = Guice.createInjector(new GuiceConfiguration());
MyComponent component = injector.getInstance(MyComponent.class);
component.after(); // @PostConstruct is not automatically called
component.performanceCriticalFeature();
assertThat(component.registry).isInstanceOf(SimpleMeterRegistry.class);
component.registry.mustFind("feature.counter").counter();
}
示例11: setUp
import com.google.inject.Guice; //导入方法依赖的package包/类
@BeforeEach
public void setUp() {
Injector injector =
Guice.createInjector(
Modules.override(new AuthenticationModule(), new ConfigurationModule())
.with(new MongoOverrideModule()));
injector.injectMembers(this);
when(mongoProvider.provide()).thenReturn(getMongoClient());
}
示例12: construct
import com.google.inject.Guice; //导入方法依赖的package包/类
public static GuiceModule construct(Context context) {
if (singleton == null) {
synchronized (lock) {
if (singleton == null) {
singleton = new GuiceModule(context.getApplicationContext());
singleton.injector = Guice.createInjector(singleton);
}
}
}
return singleton;
}
示例13: createInjector
import com.google.inject.Guice; //导入方法依赖的package包/类
public Injector createInjector() {
return Guice.createInjector(new PkmntcgoRuntimeModule());
}
示例14: setUpAndOverrideMainModule
import com.google.inject.Guice; //导入方法依赖的package包/类
public final void setUpAndOverrideMainModule(GuiceModuleConfiguration config, Module... modules) {
List<Module> moduleList = new ArrayList<Module>();
moduleList.addAll(Arrays.asList(modules));
injector = Guice.createInjector(Modules.override(new TestGuiceModule(config)).with(moduleList));
}
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:6,代码来源:AbstractTestBaseWithoutAutoInjectorInit.java
示例15: createInjector
import com.google.inject.Guice; //导入方法依赖的package包/类
public Injector createInjector() {
return Guice.createInjector(new TypesRuntimeModule());
}