Skip to content

Instantly share code, notes, and snippets.

@guliash
Created August 13, 2017 08:41
Show Gist options
  • Save guliash/e4fe849c7923feeecd9746853517a1d5 to your computer and use it in GitHub Desktop.
Save guliash/e4fe849c7923feeecd9746853517a1d5 to your computer and use it in GitHub Desktop.
Reusable
@Component(modules = MyModule.class)
public interface ComponentA {
OkHttpClient a();
SubcomponentB subcomponentB();
SubcomponentC subcomponentC();
}
@Module
public class MyModule {
@Reusable
@Provides
public OkHttpClient a() {
return new OkHttpClient();
}
}
@Subcomponent
public interface SubcomponentB {
OkHttpClient a();
}
@Subcomponent
public interface SubcomponentC {
OkHttpClient a();
}
public class OkHttpClient {
public OkHttpClient() {
}
}
public class Main {
public static void main(String[] args) {
ComponentA componentA = DaggerComponentA.create();
System.out.println(componentA.subcomponentB().a());
System.out.println(componentA.subcomponentC().a());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment