android10 / android10/Android-CleanArchitecture

Best practice to pass dynamic parameters to an UseCase?

Open
#32 26 comments 4 reactions 0 assignees View on GitHub
discussion question
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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.