-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Description
It seems like your original solution had a
datamodule dependency trying to be used in thedomainmodule. In this architecture, that is not possible.To keep in-line with what @android10 has created, you may have to create a LoginRepository (or just add a login function to the UserRepository in the existing implementation) like so:
public interface LoginRepository { Observable logUserIn(String email, String password) }Still in the
domainlayer, have a LoginUseCase that uses the LoginRepository as a component, like so:public class LoginUseCase extends UseCase { private final int userId; private final LoginRepository loginRepository; private final String email; private final String password; @Inject public LoginUseCase(int userId, LoginRepository loginRepository, ThreadExecutor threadExecutor, PostExecutionThread postExecutionThread, String email, String password) { super(threadExecutor, postExecutionThread); this.userId = userId; this.loginRepository = loginRepository; this.email = email; this.password = password; } @Override protected Observable buildUseCaseObservable() { return this.loginRepository.logUserIn(email, password); } }The
datalayer process might be a bit more involved. This is where you would actually implement your repository pattern for the login case. If you want some sort of login persistence, you will need to implement some form of SharedPreferences or SQLite for storing the data on a successful login, as well as an API to handle the initial request. I won't get too much into that here, as it is quite involved depending on your implementation.In the
presentationlayer, you would inject your LoginRepository from thedomainlayer to use wherever that dependency is needed. It would be advantageous to check if a user is logged in, and have signOut and other important methods in the repository to maintain persistence.This isn't a great implementation by any means, and may even be too complex for your needs. I'm still learning how this architecture works myself, and this is just how I see that a login implementation may work.
Hope this helps.
Let me know if you have any questions.