當前位置: 首頁>>代碼示例>>Java>>正文


Java Modules類代碼示例

本文整理匯總了Java中com.google.inject.util.Modules的典型用法代碼示例。如果您正苦於以下問題:Java Modules類的具體用法?Java Modules怎麽用?Java Modules使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Modules類屬於com.google.inject.util包,在下文中一共展示了Modules類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setUpClass

import com.google.inject.util.Modules; //導入依賴的package包/類
@BeforeClass
public static void setUpClass() throws Exception {
  faker = new Faker();
  String ip = esContainer.getContainerIpAddress();
  Integer transportPort = esContainer.getMappedPort(9300);
  MapConfiguration memoryParams = new MapConfiguration(new HashMap<>());
  memoryParams.setProperty(CONFIG_ES_CLUSTER_HOST, ip);
  memoryParams.setProperty(CONFIG_ES_CLUSTER_PORT, transportPort);
  memoryParams.setProperty(CONFIG_ES_CLUSTER_NAME, "elasticsearch");
  injector = Guice.createInjector(
      Modules.override(new ElasticSearchModule())
          .with(binder -> {
            binder.bind(Configuration.class).toProvider(() -> memoryParams);
          })
  );
  productDao = injector.getInstance(ProductDao.class);
  esClient = injector.getInstance(TransportClient.class);
}
 
開發者ID:email2liyang,項目名稱:grpc-mate,代碼行數:19,代碼來源:ProductDaoTest.java

示例2: newIsisWicketModule

import com.google.inject.util.Modules; //導入依賴的package包/類
@Override
protected Module newIsisWicketModule() {
    final Module isisDefaults = super.newIsisWicketModule();
    
    final Module overrides = new AbstractModule() {
        @Override
        protected void configure() {
            bind(ComponentFactoryRegistrar.class).to(MyComponentFactoryRegistrar.class);

            bind(String.class).annotatedWith(Names.named("applicationName")).toInstance("RotaBuilder");
            bind(String.class).annotatedWith(Names.named("applicationCss")).toInstance("css/application.css");
            bind(String.class).annotatedWith(Names.named("applicationJs")).toInstance("scripts/application.js");
            bind(String.class).annotatedWith(Names.named("welcomeMessage")).toInstance(readLines(getClass(), "welcome.html"));
            bind(String.class).annotatedWith(Names.named("aboutMessage")).toInstance("RotaBuilder");
            bind(InputStream.class).annotatedWith(Names.named("metaInfManifest")).toProvider(
                    Providers.of(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF")));
            // if uncommented, then overrides isis.appManifest in config file.
            // bind(AppManifest.class).toInstance(new DomainAppAppManifest());
        }
    };

    return Modules.override(isisDefaults).with(overrides);
}
 
開發者ID:bibryam,項目名稱:rotabuilder,代碼行數:24,代碼來源:DomainApplication.java

示例3: setUp

import com.google.inject.util.Modules; //導入依賴的package包/類
@BeforeEach
public void setUp() {
  Injector injector =
      Guice.createInjector(
          Modules.override(
                  new DatasetModule(), new CannedDatasetsModule(), new ConfigurationModule())
              .with(
                  new MongoOverrideModule(),
                  new AbstractModule() {
                    @Override
                    protected void configure() {
                      bind(CannedDatasetsLoader.class)
                          .toInstance(Mockito.mock(CannedDatasetsLoader.class));
                    }
                  }));
  injector.injectMembers(this);

  when(mongoProvider.provide()).thenReturn(getMongoClient());
}
 
開發者ID:glytching,項目名稱:dragoman,代碼行數:20,代碼來源:MongoCannedDatasetsWriterTest.java

示例4: setUp

import com.google.inject.util.Modules; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
  String ip = esContainer.getContainerIpAddress();
  Integer transportPort = esContainer.getMappedPort(9300);
  MapConfiguration memoryParams = new MapConfiguration(new HashMap<>());
  memoryParams.setProperty(CONFIG_ES_CLUSTER_HOST, ip);
  memoryParams.setProperty(CONFIG_ES_CLUSTER_PORT, transportPort);
  memoryParams.setProperty(CONFIG_ES_CLUSTER_NAME, "elasticsearch");
  Injector injector = Guice.createInjector(
      Modules.override(new ElasticSearchModule()).with(
          binder -> {
            binder.bind(Configuration.class).toInstance(memoryParams);
          }
      )
  );
  transportClientProvider = injector.getInstance(TransportClientProvider.class);
}
 
開發者ID:email2liyang,項目名稱:grpc-mate,代碼行數:18,代碼來源:TransportClientProviderTest.java

示例5: setUp

import com.google.inject.util.Modules; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
  faker = new Faker();
  productDao = mock(ProductDao.class);
  injector = Guice.createInjector(
      Modules.override(new ElasticSearchModule())
          .with(binder -> {
            binder.bind(ProductDao.class).toProvider(() -> productDao);
          })
  );

  productUpdateService = injector.getInstance(ProductUpdateService.class);
  grpcServerRule.getServiceRegistry().addService(productUpdateService);

  stub = ProductUpdateServiceGrpc.newStub(grpcServerRule.getChannel());
}
 
開發者ID:email2liyang,項目名稱:grpc-mate,代碼行數:17,代碼來源:ProductUpdateServiceTest.java

示例6: setup

import com.google.inject.util.Modules; //導入依賴的package包/類
@Before
public void setup() {
    Injector injector = Guice.createInjector(
            Modules.override(new PolicyModule()
            ).with(new AbstractModule() {
                @Override
                protected void configure() {
                    bind(EventSinkProxy.class).toInstance(mock(EventSinkProxy.class));
                    bind(IdentityProvidersConfigProxy.class).toInstance(mock(IdentityProvidersConfigProxy.class));
                    bind(Client.class).toInstance(mock(Client.class));
                    bind(Environment.class).toInstance(mock(Environment.class));
                    bind(PolicyConfiguration.class).toInstance(aPolicyConfiguration().build());
                    InfinispanCacheManager infinispanCacheManager = anInfinispanCacheManager().build(InfinispanJunitRunner.EMBEDDED_CACHE_MANAGER);
                    bind(InfinispanCacheManager.class).toInstance(infinispanCacheManager);
                    bind(EventSinkHubEventLogger.class).toInstance(mock(EventSinkHubEventLogger.class));
                    bind(JsonClient.class).annotatedWith(Names.named("samlSoapProxyClient")).toInstance(mock(JsonClient.class));
                    bind(JsonClient.class).toInstance(mock(JsonClient.class));
                }
            })
    );

    factory = new StateControllerFactory(injector);
}
 
開發者ID:alphagov,項目名稱:verify-hub,代碼行數:24,代碼來源:StateControllerFactoryTest.java

示例7: createModule

import com.google.inject.util.Modules; //導入依賴的package包/類
@Override
public Module createModule(ITestContext context, Class<?> testClass){

	Module globalModule = new AbstractModule(){

		@Override
		protected void configure(){
			for(Module module : modules){
				install(module);
			}
		}

	};
	Iterable<? extends Module> overriders = getOverriders();
	return Modules.override(globalModule).with(overriders);
}
 
開發者ID:hotpads,項目名稱:datarouter,代碼行數:17,代碼來源:ModuleFactory.java

示例8: newIsisWicketModule

import com.google.inject.util.Modules; //導入依賴的package包/類
@Override
 protected Module newIsisWicketModule() {
     final Module isisDefaults = super.newIsisWicketModule();
     
     final Module overrides = new AbstractModule() {
         @Override
         protected void configure() {
             bind(String.class).annotatedWith(Names.named("applicationName")).toInstance("SiGeSe");
             bind(String.class).annotatedWith(Names.named("applicationCss")).toInstance("css/application.css");
             bind(String.class).annotatedWith(Names.named("applicationJs")).toInstance("scripts/application.js");
	bind(String.class).annotatedWith(Names.named("brandLogoSignin")).toInstance("/about/images/login.png");
	bind(String.class).annotatedWith(Names.named("welcomeMessage")).toInstance(readLines(getClass(), "welcome.html"));
	bind(String.class).annotatedWith(Names.named("aboutMessage")).toInstance("SiGeSe");
	bind(InputStream.class).annotatedWith(Names.named("metaInfManifest")).toProvider(Providers.of(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF")));
}
     };

     return Modules.override(isisDefaults).with(overrides);
 }
 
開發者ID:leandrogonqn,項目名稱:Proyecto2017Seguros,代碼行數:20,代碼來源:PacinetesApplication.java

示例9: configModuleWithOverrides

import com.google.inject.util.Modules; //導入依賴的package包/類
private static <C> Module configModuleWithOverrides(final Class<C> configInterface, final Optional<Named> nameOpt, final Optional<OverrideConsumer<C>> overrideOpt)
{
    checkNotNull(configInterface);
    checkNotNull(nameOpt);
    checkNotNull(overrideOpt);

    if (overrideOpt.isPresent()) {
        return Modules.override(ConfigBuilder.configModule(configInterface, nameOpt))
            .with(new OverrideModule<C>(configInterface, nameOpt.map(n -> n.value()))
            {
                @Override
                protected void configure()
                {
                    overrideOpt.get().accept(this);
                }
            });
    }
    else {
        return ConfigBuilder.configModule(configInterface, nameOpt);
    }
}
 
開發者ID:kikinteractive,項目名稱:ice,代碼行數:22,代碼來源:ConfigSystem.java

示例10: testExample1

import com.google.inject.util.Modules; //導入依賴的package包/類
@Test(timeout = 5000)
@SuppressWarnings("UnnecessaryUnboxing")
public void testExample1() throws Exception
{
    Injector injector = Guice.createInjector(Modules.override(
        ConfigConfigurator.standardModules(),
        Example1.module())
        .with(new AbstractModule()
        {
            @Override
            protected void configure()
            {
                bind(String.class).annotatedWith(named(FileDynamicConfigSource.FILENAME_NAME)).toInstance(getClass().getResource("Example1.config").getFile());
            }
        })
    );

    injector.injectMembers(this);

    assertNotNull(example);
    example.doStuff();

    assertEquals("testFoo", example.config.connectionString());
    assertEquals(123L, example.config.connectionTimeout().longValue());
    assertEquals(Duration.parse("P1DT2H32M18S"), example.config.delayTime());
}
 
開發者ID:kikinteractive,項目名稱:ice,代碼行數:27,代碼來源:Example1Test.java

示例11: setup

import com.google.inject.util.Modules; //導入依賴的package包/類
@Before
public void setup()
{
    final Named name = Names.named("provider-test");

    Module module = Modules.override(
        ConfigConfigurator.testModules(),
        ProviderExample.module(name)
    ).with(new AbstractModule()
    {
        @Override
        protected void configure()
        {
            install(ConfigSystem.overrideModule(ProviderExample.Config.class, name, om -> {
                om.override(om.id().connectionString()).withValue("foo bar");
                om.override(om.id().keyspaceName()).withValue("keyspace baz");
            }));
        }
    });

    Guice.createInjector(module).injectMembers(this);
}
 
開發者ID:kikinteractive,項目名稱:ice,代碼行數:23,代碼來源:ProviderExampleTest.java

示例12: 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)
  );
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:32,代碼來源:DbModule.java

示例13: 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);
        }
      });
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:19,代碼來源:HttpSecurityIT.java

示例14: setUp

import com.google.inject.util.Modules; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
  stateManager = createMock(StateManager.class);
  storage = DbUtil.createStorage();
  auroraCronJob = createMock(AuroraCronJob.class);

  injector = Guice.createInjector(
      // Override to verify that Guice is actually used for construction of the AuroraCronJob.
      // TODO(ksweeney): Use the production class here.
      Modules.override(new CronModule()).with(new AbstractModule() {
        @Override
        protected void configure() {
          bind(AuroraCronJob.class).toInstance(auroraCronJob);
        }
      }), new AbstractModule() {
        @Override
        protected void configure() {
          bind(ConfigurationManager.class).toInstance(TaskTestUtil.CONFIGURATION_MANAGER);
          bind(Clock.class).toInstance(Clock.SYSTEM_CLOCK);
          bind(StateManager.class).toInstance(stateManager);
          bind(Storage.class).toInstance(storage);
        }
      });
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:25,代碼來源:CronIT.java

示例15: 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()));
          }
        }
      });
}
 
開發者ID:ArloJamesBarnes,項目名稱:walkaround,代碼行數:26,代碼來源:GuiceSetup.java


注:本文中的com.google.inject.util.Modules類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。