android10 / android10/Android-CleanArchitecture
How to deal with login?
- Lenguaje dominante
- Java
- Estrellas
- 15.5k
- Forks
- 3.3k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
## 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?**
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Evaluación
Este issue todavía no se ha evaluado.