I am using repository pattern in mvp with dagger .In App scope I binded my RemoteDataSource and LocalDataSource:
@Binds
@AppScope
@Remote
abstract MainDataSource RemoteDataSource(RemoteDataSource remoteDataSource);
@Binds
@AppScope
@Local
abstract MainDataSource LocalDataSource(LocalDataSource localDataSource);
And i injected main repository in app scope:
@Inject
public MainRepository(@Remote MainDataSource remoteDataSource,
@Local MainDataSource localDataSource) {
this.remoteDataSource = checkNotNull(remoteDataSource);
this.localDataSource = checkNotNull(localDataSource);
}
Now in fragment scope in mainpresenter
i passed MainRepository in it's contractor :
@MainFragScope
@Component(modules = {MainFragModule.class}, dependencies = AppComponent.class)
public interface MainFragComponent {
Presenter constructor:
private MainDataSource remoteDataSource;
private MainDataSource localDataSource;
@Inject
public MainPresenter(MainRepository repository, ArrayAdapter<String> typesAdapter) {
this.repository = checkNotNull(repository);
this.typesAdapter = checkNotNull(typesAdapter);
}
@Override
public void loadChart(String district, String date, String type) {
remoteDataSource.loadChart(district,date,type);
}
In RemoteDataSource
i have a method called loadChart
and it's job is fetch data from remote server by retrofit:
public void loadChart(String district, String date, String type) {
JsonObject joParam = new JsonObject();
apiService.getAnalyticalReport(joParam).enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
try {
if (response.isSuccessful()) {
// need presenter reference to pass response to it
After fetching data i need to return this data from server to fragment presenter(MainPresenter).I need to presenter reference. How could i get presenter without destroy mvp roles!!? Because in AppScope i do not access to MainPresenter.