当前位置: 首页>>代码示例>>Java>>正文


Java Guice.createInjector方法代码示例

本文整理汇总了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());
}
 
开发者ID:KyoriPowered,项目名称:violet,代码行数:19,代码来源:VBinderTest.java

示例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);
}
 
开发者ID:KyoriPowered,项目名称:violet,代码行数:19,代码来源:LazyTest.java

示例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();
}
 
开发者ID:mnemonic-no,项目名称:act-platform,代码行数:21,代码来源:AbstractIT.java

示例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);
    }
}
 
开发者ID:hristo-vrigazov,项目名称:bromium,代码行数:23,代码来源:DefaultModuleTest.java

示例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);
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:22,代码来源:TestHandlerInterception.java

示例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());
}
 
开发者ID:hermannpencole,项目名称:nifi-config,代码行数:28,代码来源:PortServiceTest.java

示例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;
}
 
开发者ID:thingleme,项目名称:java8-jersey2-guice4-webapp,代码行数:14,代码来源:AppServletContextListener.java

示例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);
}
 
开发者ID:lemonJun,项目名称:TakinRPC,代码行数:11,代码来源:RaftService.java

示例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();
    }
}
 
开发者ID:vy,项目名称:hrrs,代码行数:15,代码来源:Distiller.java

示例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();
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:10,代码来源:MeterRegistryInjectionTest.java

示例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());
}
 
开发者ID:glytching,项目名称:dragoman,代码行数:11,代码来源:MongoAuthenticationDaoTest.java

示例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;
}
 
开发者ID:bunnyblue,项目名称:NoticeDog,代码行数:12,代码来源:GuiceModule.java

示例13: createInjector

import com.google.inject.Guice; //导入方法依赖的package包/类
public Injector createInjector() {
	return Guice.createInjector(new PkmntcgoRuntimeModule());
}
 
开发者ID:rehne93,项目名称:pokemon-tcgo-deck-generator,代码行数:4,代码来源:PkmntcgoStandaloneSetupGenerated.java

示例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());
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:4,代码来源:TypesStandaloneSetupGenerated.java


注:本文中的com.google.inject.Guice.createInjector方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。