I tried to do SubScoping in Dagger2. However, I can not understand this compilation error: → ...MyApplicationModule must be set, which occurs in mine LogInFragment. If someone tries to shed light on this mistake. I really would be glad.
This is the MyApplication class :
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
MyInjector.initialize(this);
}
}
This is the MyInjector class:
public enum MyInjector {
INSTANCE;
MyApplicationComponent myApplicationComponent;
private MyInjector() {
}
public static void initialize(MyApplication myApplication) {
MyApplicationComponent myApplicationComponent = DaggerMyApplicationComponent.builder()
.myApplicationModule(new MyApplicationModule(myApplication))
.build();
INSTANCE.myApplicationComponent = myApplicationComponent;
}
public static MyApplicationComponent get() {
return INSTANCE.myApplicationComponent;
}
}
This is the MyApplicationComponent class:
@Component (modules = {MyApplicationModule.class})
public interface MyApplicationComponent {
}
This is the class MyApplicationModule
@Module
public class MyApplicationModule {
private final MyApplication myApplication;
public MyApplicationModule(MyApplication myApplication) {
this.myApplication = myApplication;
}
@Singleton
@Provides
SharedPreferences providesSharedPreferences(Context context) {
return context.getSharedPreferences("My_Pref", Context.MODE_PRIVATE);
}
@Singleton
@Provides
public Context providesMyApplicationContext() {
return this.myApplication.getApplicationContext();
}
@Singleton
@Provides
public LocationManager providesLocationService(Context context) {
return (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
}
@Singleton
@Provides
public MyDatabaseManager providesMyDatabaseManager(Context context) {
return MyDatabaseManager.getInstance(context);
}
@Singleton
@Provides
public AccountSystemModel providesAccountSystemModel(Context context) {
return MyDatabaseManager.getInstance(context);
}
@Singleton
@Provides
public MyApplication providesMyApplication(){
return this.myApplication;
}
}
Here i'm trying subscope
This is the MyLogIn Component Class
@Singleton
@Component(modules = {MyApplicationModule.class}, dependencies = {MyApplicationComponent.class})
public interface LogInComponent {
LogInPresenter signInPresenter();
}
here Compilation Errorcomes
This is MyLogInActivityFragment
@Override protected void injectDependencies() {
logInComponent = DaggerLogInComponent.builder()
.myApplicationComponent(MyInjector.get())
.build();
}