Search in sources :

Example 71 with FactoryModuleBuilder

use of com.google.inject.assistedinject.FactoryModuleBuilder in project guice by google.

the class SubpackageTest method testPrivateFallbackOnly.

@Test
public void testPrivateFallbackOnly() throws Exception {
    // Private fallback only works on JDKs below 17. On 17+ it's disabled.
    assumeTrue(JAVA_VERSION < 17);
    setAllowMethodHandleWorkaround(false);
    Injector injector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            install(new FactoryModuleBuilder().build(ConcreteAssistedWithOverride.Factory.class));
        }
    });
    LogRecord record = Iterables.getOnlyElement(logRecords);
    assertThat(record.getMessage()).contains("Please pass a `MethodHandles.lookup()`");
    ConcreteAssistedWithOverride.Factory factory = injector.getInstance(ConcreteAssistedWithOverride.Factory.class);
    factory.create("foo");
    AbstractAssisted.Factory<ConcreteAssistedWithOverride, String> factoryAbstract = factory;
    factoryAbstract.create("foo");
}
Also used : LogRecord(java.util.logging.LogRecord) Injector(com.google.inject.Injector) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Example 72 with FactoryModuleBuilder

use of com.google.inject.assistedinject.FactoryModuleBuilder in project guice by google.

the class SubpackageTest method testHandleWorkaroundOnly.

@Test
public void testHandleWorkaroundOnly() throws Exception {
    setAllowPrivateLookupFallback(false);
    Injector injector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            install(new FactoryModuleBuilder().build(ConcreteAssistedWithOverride.Factory.class));
        }
    });
    LogRecord record = Iterables.getOnlyElement(logRecords);
    assertThat(record.getMessage()).contains("Please pass a `MethodHandles.lookup()`");
    ConcreteAssistedWithOverride.Factory factory = injector.getInstance(ConcreteAssistedWithOverride.Factory.class);
    factory.create("foo");
    AbstractAssisted.Factory<ConcreteAssistedWithOverride, String> factoryAbstract = factory;
    factoryAbstract.create("foo");
}
Also used : LogRecord(java.util.logging.LogRecord) Injector(com.google.inject.Injector) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Example 73 with FactoryModuleBuilder

use of com.google.inject.assistedinject.FactoryModuleBuilder in project gerrit by GerritCodeReview.

the class LuceneIndexModuleOnInit method configure.

@Override
protected void configure() {
    install(new FactoryModuleBuilder().implement(AccountIndex.class, LuceneAccountIndex.class).build(AccountIndex.Factory.class));
    install(new FactoryModuleBuilder().implement(GroupIndex.class, LuceneGroupIndex.class).build(GroupIndex.Factory.class));
    install(new IndexModuleOnInit());
    bind(AutoFlush.class).toInstance(AutoFlush.DISABLED);
}
Also used : FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) AutoFlush(com.google.gerrit.server.index.options.AutoFlush) IndexModuleOnInit(com.google.gerrit.pgm.init.index.IndexModuleOnInit)

Example 74 with FactoryModuleBuilder

use of com.google.inject.assistedinject.FactoryModuleBuilder in project gerrit by GerritCodeReview.

the class DeleteZombieDrafts method getSysInjector.

private Injector getSysInjector() {
    List<Module> modules = new ArrayList<>();
    modules.add(new AbstractModule() {

        @Override
        protected void configure() {
            bind(Path.class).annotatedWith(SitePath.class).toInstance(getSitePath());
            bind(ConsoleUI.class).toInstance(ConsoleUI.getInstance(false));
            bind(String.class).annotatedWith(SecureStoreClassName.class).toProvider(Providers.of(getConfiguredSecureStoreClass()));
            bind(MetricMaker.class).to(DisabledMetricMaker.class);
            install(new FactoryModuleBuilder().build(DeleteZombieCommentsRefs.Factory.class));
        }
    });
    modules.add(new GerritServerConfigModule());
    modules.add(new SchemaModule());
    return Guice.createInjector(modules);
}
Also used : SitePath(com.google.gerrit.server.config.SitePath) Path(java.nio.file.Path) GerritServerConfigModule(com.google.gerrit.server.config.GerritServerConfigModule) SchemaModule(com.google.gerrit.server.schema.SchemaModule) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) DeleteZombieCommentsRefs(com.google.gerrit.server.notedb.DeleteZombieCommentsRefs) ArrayList(java.util.ArrayList) Module(com.google.inject.Module) GerritServerConfigModule(com.google.gerrit.server.config.GerritServerConfigModule) SchemaModule(com.google.gerrit.server.schema.SchemaModule) AbstractModule(com.google.inject.AbstractModule) DisabledMetricMaker(com.google.gerrit.metrics.DisabledMetricMaker) AbstractModule(com.google.inject.AbstractModule)

Example 75 with FactoryModuleBuilder

use of com.google.inject.assistedinject.FactoryModuleBuilder in project graylog2-server by Graylog2.

the class ServerBindings method bindInterfaces.

private void bindInterfaces() {
    bind(AlertSender.class).to(FormattedEmailAlertSender.class);
    bind(StreamRouter.class);
    install(new FactoryModuleBuilder().implement(StreamRouterEngine.class, StreamRouterEngine.class).build(StreamRouterEngine.Factory.class));
    bind(ActivityWriter.class).to(SystemMessageActivityWriter.class);
    bind(PersistedInputs.class).to(PersistedInputsImpl.class);
    bind(RoleService.class).to(RoleServiceImpl.class).in(Scopes.SINGLETON);
    OptionalBinder.newOptionalBinder(binder(), ClusterIdFactory.class).setDefault().to(RandomUUIDClusterIdFactory.class);
}
Also used : PersistedInputs(org.graylog2.shared.inputs.PersistedInputs) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) ClusterIdFactory(org.graylog2.plugin.cluster.ClusterIdFactory) SystemJobFactory(org.graylog2.system.jobs.SystemJobFactory) RandomUUIDClusterIdFactory(org.graylog2.plugin.cluster.RandomUUIDClusterIdFactory) ActivityWriter(org.graylog2.shared.system.activities.ActivityWriter) SystemMessageActivityWriter(org.graylog2.system.activities.SystemMessageActivityWriter) AlertSender(org.graylog2.alerts.AlertSender) FormattedEmailAlertSender(org.graylog2.alerts.FormattedEmailAlertSender) RoleServiceImpl(org.graylog2.users.RoleServiceImpl)

Aggregations

FactoryModuleBuilder (com.google.inject.assistedinject.FactoryModuleBuilder)85 AbstractModule (com.google.inject.AbstractModule)20 Injector (com.google.inject.Injector)12 ConfigModule (co.cask.cdap.common.guice.ConfigModule)10 PrivateModule (com.google.inject.PrivateModule)10 DatasetDefinitionRegistry (co.cask.cdap.api.dataset.module.DatasetDefinitionRegistry)8 DefaultDatasetDefinitionRegistry (co.cask.cdap.data2.dataset2.DefaultDatasetDefinitionRegistry)8 InMemoryDatasetFramework (co.cask.cdap.data2.dataset2.InMemoryDatasetFramework)8 TypeLiteral (com.google.inject.TypeLiteral)8 DatasetFramework (co.cask.cdap.data2.dataset2.DatasetFramework)7 DiscoveryRuntimeModule (co.cask.cdap.common.guice.DiscoveryRuntimeModule)6 LocationRuntimeModule (co.cask.cdap.common.guice.LocationRuntimeModule)6 SystemDatasetRuntimeModule (co.cask.cdap.data.runtime.SystemDatasetRuntimeModule)6 DatasetOpExecutor (co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutor)6 DatasetDefinitionRegistryFactory (co.cask.cdap.data2.dataset2.DatasetDefinitionRegistryFactory)6 Singleton (com.google.inject.Singleton)6 TransactionManager (org.apache.tephra.TransactionManager)6 DatasetService (co.cask.cdap.data2.datafabric.dataset.service.DatasetService)5 DatasetAdminOpHTTPHandler (co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetAdminOpHTTPHandler)5 CConfiguration (co.cask.cdap.common.conf.CConfiguration)4