Search in sources :

Example 11 with Singleton

use of javax.inject.Singleton in project guice by google.

the class MiniGuiceTest method testSingletonsAreEager.

public void testSingletonsAreEager() {
    final AtomicBoolean sInjected = new AtomicBoolean();
    R.injected = false;
    MiniGuice.inject(A.class, new Object() {

        @Provides
        F provideF(R r) {
            return new F();
        }

        @Provides
        @Singleton
        S provideS() {
            sInjected.set(true);
            return new S();
        }
    });
    assertTrue(R.injected);
    assertTrue(sInjected.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Example 12 with Singleton

use of javax.inject.Singleton in project sqlbrite by square.

the class DbModule method provideDatabase.

@Provides
@Singleton
BriteDatabase provideDatabase(SqlBrite sqlBrite, SQLiteOpenHelper helper) {
    BriteDatabase db = sqlBrite.wrapDatabaseHelper(helper, Schedulers.io());
    db.setLoggingEnabled(true);
    return db;
}
Also used : BriteDatabase(com.squareup.sqlbrite.BriteDatabase) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 13 with Singleton

use of javax.inject.Singleton in project curiostack by curioswitch.

the class FirebaseAuthModule method firebaseApp.

@Provides
@Singleton
static FirebaseApp firebaseApp(FirebaseAuthConfig config) {
    final FirebaseOptions options;
    try {
        options = new FirebaseOptions.Builder().setCredentials(GoogleCredentials.fromStream(new ByteArrayInputStream(Base64.getDecoder().decode(config.getServiceAccountBase64())))).setDatabaseUrl("https://" + config.getProjectId() + ".firebaseio.com").build();
    } catch (IOException e) {
        throw new UncheckedIOException("Could not read certificate.", e);
    }
    FirebaseApp.initializeApp(options);
    return checkNotNull(FirebaseApp.getInstance());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) FirebaseOptions(com.google.firebase.FirebaseOptions) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 14 with Singleton

use of javax.inject.Singleton in project curiostack by curioswitch.

the class DatabaseModule method dataSource.

@Provides
@Singleton
static DataSource dataSource(DatabaseConfig config) {
    HikariConfig hikari = new HikariConfig();
    hikari.setJdbcUrl(config.getJdbcUrl());
    hikari.setUsername(config.getUsername());
    hikari.setPassword(config.getPassword());
    hikari.addDataSourceProperty("cachePrepStmts", true);
    hikari.addDataSourceProperty("prepStmtCacheSize", 250);
    hikari.addDataSourceProperty("prepStmtCacheSqlLimit", 2048);
    hikari.addDataSourceProperty("useServerPrepStmts", true);
    hikari.addDataSourceProperty("useLocalSessionState", true);
    hikari.addDataSourceProperty("useLocalTransactionState", true);
    hikari.addDataSourceProperty("rewriteBatchedStatements", true);
    hikari.addDataSourceProperty("cacheResultSetMetadata", true);
    hikari.addDataSourceProperty("cacheServerConfiguration", true);
    hikari.addDataSourceProperty("elideSetAutoCommits", true);
    hikari.addDataSourceProperty("maintainTimeStats", false);
    hikari.addDataSourceProperty("statementInterceptors", "brave.mysql.TracingStatementInterceptor");
    hikari.setMetricsTrackerFactory(new PrometheusMetricsTrackerFactory());
    return new HikariDataSource(hikari);
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) PrometheusMetricsTrackerFactory(com.zaxxer.hikari.metrics.prometheus.PrometheusMetricsTrackerFactory) HikariConfig(com.zaxxer.hikari.HikariConfig) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 15 with Singleton

use of javax.inject.Singleton in project dobby-android by InceptAi.

the class ProdModule method providesNetworkLayer.

@Singleton
@Provides
public NetworkLayer providesNetworkLayer(DobbyApplication application, DobbyThreadpool threadpool, DobbyEventBus eventBus) {
    NetworkLayer networkLayer = new NetworkLayer(application.getApplicationContext(), threadpool, eventBus);
    application.getProdComponent().inject(networkLayer);
    networkLayer.initialize();
    return networkLayer;
}
Also used : NetworkLayer(com.inceptai.dobby.NetworkLayer) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Aggregations

Singleton (javax.inject.Singleton)168 Provides (dagger.Provides)98 Provides (com.google.inject.Provides)57 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)21 Named (javax.inject.Named)17 OkHttpClient (okhttp3.OkHttpClient)17 Cache (okhttp3.Cache)10 List (java.util.List)9 ConfigBinder.configBinder (com.facebook.airlift.configuration.ConfigBinder.configBinder)8 Binder (com.google.inject.Binder)8 Module (com.google.inject.Module)8 CachingStripeMetadataSource (com.facebook.presto.orc.CachingStripeMetadataSource)7 DwrfAwareStripeMetadataSourceFactory (com.facebook.presto.orc.DwrfAwareStripeMetadataSourceFactory)7 OrcDataSourceId (com.facebook.presto.orc.OrcDataSourceId)7 StorageStripeMetadataSource (com.facebook.presto.orc.StorageStripeMetadataSource)7 StripeMetadataSource (com.facebook.presto.orc.StripeMetadataSource)7 StripeMetadataSourceFactory (com.facebook.presto.orc.StripeMetadataSourceFactory)7 CachingOrcFileTailSource (com.facebook.presto.orc.cache.CachingOrcFileTailSource)7 OrcCacheConfig (com.facebook.presto.orc.cache.OrcCacheConfig)7 OrcFileTailSource (com.facebook.presto.orc.cache.OrcFileTailSource)7