android10 / android10/Android-CleanArchitecture
How to deal with login?
- Ngôn ngữ chính
- Java
- Star
- 15.5k
- Fork
- 3.3k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
## Introduction:
At the `data layer` I have retrofit-interface. For example:
```
public interface SomeApi {
@POST(...)
Observable login(LoginRequest body);
}
```
At the `domain layer` I have `AccountManger`:
```
public class AccountManager {
private SomeApi api;
@Inject
public AccountManager(SomeApi api) { // errot: SomeApi out of classpath
this.api = api;
}
public void login(String login, String password, Subscriber subscriber) {
api.login(...) ...
}
}
```
And then I would use `AccountManager`in `presentation layer`.
But. Nope. Compile time error.
`SomeApi` is in `data module` classpath, because `domain module` has no gradle dependency on `data module` as `data module` has android dependency while `domain module` hasn't.
## There is my solution:
Create `LoginApi` interface:
```
public interface LoginApi {
Observable login(LoginRequest body);
}
```
Use it in `AccountManager`:
```
public class AccountManager {
private LoginApi api;
@Inject
public AccountManager(LoginApi api) {
this.api = api;
}
...
}
```
Create implementation of `LoginApi` on `data-layer` that use `SomeApi`:
```
public class LoginApiImpl implement LoginApi {
private SomeApi api;
@Inject
public LoginApiImpl(SomeApi api) {
this.api = api;
}
Observable login(LoginRequest body) {
return api.login(body);
}
}
```
And inject it via Dagger 2 in `presentation layer`.
**Any other ideas?**
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Đánh giá
Issue này chưa được đánh giá.