Should I use one component for each operation in dagger 2?

I have the following dependencies in an android app. What is the best way to do this in dagger 2?

Activity A ----  Adapter A and Adapter B and SharedPreferences
Activity B ----  Adapter B and SharedPreferences
Activity C ----  Adapter C and SharedPreferences

Should I create a separate component for each operation? Should there be three separate components?

+4
source share
1 answer

2 Android. . ( ). Google Android Architecture Blueprints Github repo. , , ( ), Activity Fragment, . , , .

. , , , , , . , . , , , B C.

, , . , , , , , .

, , :

@Component( modules = { SharedPreferencesModule.class } )
@PerApp
interface AppComponent {

    SharedPreferences sharedPreferences(Application app);

}

Activity, . , SharedPreferences, :

@Component( dependencies = { AppComponent.class }, modules = { AdapterAModule.class } )
@PerActivity
interface ActivityAComponent {

}
+8

Source: https://habr.com/ru/post/1664609/


All Articles