Search in sources :

Example 61 with Singleton

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

the class DbModule method provideDatabase.

@Provides
@Singleton
BriteDatabase provideDatabase(SqlBrite sqlBrite, Application application) {
    Configuration configuration = Configuration.builder(application).name("todo.db").callback(new DbCallback()).build();
    Factory factory = new FrameworkSQLiteOpenHelperFactory();
    SupportSQLiteOpenHelper helper = factory.create(configuration);
    BriteDatabase db = sqlBrite.wrapDatabaseHelper(helper, Schedulers.io());
    db.setLoggingEnabled(true);
    return db;
}
Also used : FrameworkSQLiteOpenHelperFactory(android.arch.persistence.db.framework.FrameworkSQLiteOpenHelperFactory) SupportSQLiteOpenHelper(android.arch.persistence.db.SupportSQLiteOpenHelper) Configuration(android.arch.persistence.db.SupportSQLiteOpenHelper.Configuration) FrameworkSQLiteOpenHelperFactory(android.arch.persistence.db.framework.FrameworkSQLiteOpenHelperFactory) Factory(android.arch.persistence.db.SupportSQLiteOpenHelper.Factory) BriteDatabase(com.squareup.sqlbrite3.BriteDatabase) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 62 with Singleton

use of javax.inject.Singleton in project MVPArms by JessYanCoding.

the class ClientModule method provideClient.

/**
 * 提供 {@link OkHttpClient}
 *
 * @param application     {@link Application}
 * @param configuration   {@link OkhttpConfiguration}
 * @param builder         {@link OkHttpClient.Builder}
 * @param intercept       {@link Interceptor}
 * @param interceptors    {@link List<Interceptor>}
 * @param handler         {@link GlobalHttpHandler}
 * @param executorService {@link ExecutorService}
 * @return {@link OkHttpClient}
 */
@Singleton
@Provides
static OkHttpClient provideClient(Application application, @Nullable OkhttpConfiguration configuration, OkHttpClient.Builder builder, Interceptor intercept, @Nullable List<Interceptor> interceptors, @Nullable GlobalHttpHandler handler, ExecutorService executorService) {
    builder.connectTimeout(TIME_OUT, TimeUnit.SECONDS).readTimeout(TIME_OUT, TimeUnit.SECONDS).addNetworkInterceptor(intercept);
    if (handler != null) {
        builder.addInterceptor(chain -> chain.proceed(handler.onHttpRequestBefore(chain, chain.request())));
    }
    // 如果外部提供了 Interceptor 的集合则遍历添加
    if (interceptors != null) {
        for (Interceptor interceptor : interceptors) {
            builder.addInterceptor(interceptor);
        }
    }
    // 为 OkHttp 设置默认的线程池
    builder.dispatcher(new Dispatcher(executorService));
    if (configuration != null) {
        configuration.configOkhttp(application, builder);
    }
    return builder.build();
}
Also used : Dispatcher(okhttp3.Dispatcher) RequestInterceptor(com.jess.arms.http.log.RequestInterceptor) Interceptor(okhttp3.Interceptor) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 63 with Singleton

use of javax.inject.Singleton in project MVPArms by JessYanCoding.

the class ClientModule method provideRxCache.

/**
 * 提供 {@link RxCache}
 *
 * @param application    {@link Application}
 * @param configuration  {@link RxCacheConfiguration}
 * @param cacheDirectory RxCache 缓存路径
 * @param gson           {@link Gson}
 * @return {@link RxCache}
 */
@Singleton
@Provides
static RxCache provideRxCache(Application application, @Nullable RxCacheConfiguration configuration, @Named("RxCacheDirectory") File cacheDirectory, Gson gson) {
    RxCache.Builder builder = new RxCache.Builder();
    RxCache rxCache = null;
    if (configuration != null) {
        rxCache = configuration.configRxCache(application, builder);
    }
    if (rxCache != null) {
        return rxCache;
    }
    return builder.persistence(cacheDirectory, new GsonSpeaker(gson));
}
Also used : GsonSpeaker(io.victoralbertos.jolyglot.GsonSpeaker) RxCache(io.rx_cache2.internal.RxCache) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 64 with Singleton

use of javax.inject.Singleton in project philm by chrisbanes.

the class NetworkProvider method provideTraktClient.

@Provides
@Singleton
public Trakt provideTraktClient(@CacheDirectory File cacheLocation) {
    Trakt trakt = new PhilmTrakt(cacheLocation);
    trakt.setApiKey(Constants.TRAKT_API_KEY);
    trakt.setIsDebug(Constants.DEBUG_NETWORK);
    return trakt;
}
Also used : PhilmTrakt(app.philm.in.network.PhilmTrakt) Trakt(com.jakewharton.trakt.Trakt) PhilmTrakt(app.philm.in.network.PhilmTrakt) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 65 with Singleton

use of javax.inject.Singleton in project android-oss by kickstarter.

the class ApplicationModule method provideHttpLoggingInterceptor.

@Provides
@Singleton
@NonNull
static HttpLoggingInterceptor provideHttpLoggingInterceptor() {
    final HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
    return interceptor;
}
Also used : HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) Singleton(javax.inject.Singleton) NonNull(androidx.annotation.NonNull) 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