android10 / android10/Android-CleanArchitecture
Best practice to pass dynamic parameters to an UseCase?
- Dominant language
- Java
- Stars
- 15.5k
- Forks
- 3.3k
- PR merge metrics
- No merged PRs in 30d
Description
As in the example, usecase's parameters are set via `UserModule`:
``` java
@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`.
``` java
public interface UserIdProvider {
int getUserId();
}
```
Any suggestion, recommendation?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.