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());
}
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;
}
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());
}
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);
}
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;
}
Aggregations