Best practice to pass dynamic parameters to an UseCase?
Author: rockerhieuCreated Jul 5, 2015Updated Nov 28, 2020
Labelsquestiondiscussion
As in the example, usecase's parameters are set via UserModule:
@Module
public class UserModule {
private int userId = -1;
public UserModule() {}
public UserModule(int userId) {
this.userId = userId;
}
@Provides @PerActivity @Named("userDetails") UseCase provideGetUserDetailsUseCase(
UserRepository userRepository, ThreadExecutor threadExecutor,
PostExecutionThread postExecutionThread) {
return new GetUserDetailsUseCase(userId, userRepository, threadExecutor, postExecutionThread);
}
}But there are some cases when buildUseCaseObservable depends on some dynamic parameters. I tried to create an interface to provide these parameters and let the view (in MVP) implement it and pass them to UserModule. With this approach if the view is a Fragment then I have to re-create UserModule again in the Fragment.
public interface UserIdProvider {
int getUserId();
}Any suggestion, recommendation?
Source: android10/Android-CleanArchitecture