Slide 77
Slide 77 text
This is how we use
@Scope
@Scope
@Retention(RetentionPolicy.CLA
SS)
public @interface
RandomUserApplicationScope {
}
This is how we will use our customly created Scope:
● Firstly, we have to put it at component level:
@RandomUserApplicationScope
@Component(modules = {RandomUserServiceModule.class,
PicassoModule.class})
public interface RandomUserApplicationComponent {}
● Then, put it on every method with @Provides, that needs to act
as Singleton. Usually, we need just single instance for
OkhttpClient, Picasso, etc:
@Provides
@RandomUserApplicationScope
public Picasso picasso(Context context, OkHttp3Downloader
okHttp3Downloader) {}
@Provides
@RandomUserApplicationScope
public Retrofit retrofit(OkHttpClient okHttpClient,
GsonConverterFactory gsonConverterFactory) {}