Let dagger manage domain objects instances.

This commit is contained in:
Fernando Cejas
2015-03-06 22:06:29 +01:00
parent 7ecdb98d12
commit 20a74ca865
3 changed files with 12 additions and 7 deletions

View File

@ -9,11 +9,14 @@ import com.fernandocejas.android10.sample.domain.exception.ErrorBundle;
import com.fernandocejas.android10.sample.domain.executor.PostExecutionThread;
import com.fernandocejas.android10.sample.domain.executor.ThreadExecutor;
import com.fernandocejas.android10.sample.domain.repository.UserRepository;
import javax.inject.Inject;
import javax.inject.Singleton;
/**
* This class is an implementation of {@link GetUserDetailsUseCase} that represents a use case for
* retrieving data related to an specific {@link User}.
*/
@Singleton
public class GetUserDetailsUseCaseImpl implements GetUserDetailsUseCase {
private final UserRepository userRepository;
@ -32,6 +35,7 @@ public class GetUserDetailsUseCaseImpl implements GetUserDetailsUseCase {
* @param postExecutionThread {@link PostExecutionThread} used to post updates when the use case
* has been executed.
*/
@Inject
public GetUserDetailsUseCaseImpl(UserRepository userRepository, ThreadExecutor threadExecutor,
PostExecutionThread postExecutionThread) {
if (userRepository == null || threadExecutor == null || postExecutionThread == null) {

View File

@ -10,11 +10,14 @@ import com.fernandocejas.android10.sample.domain.executor.PostExecutionThread;
import com.fernandocejas.android10.sample.domain.executor.ThreadExecutor;
import com.fernandocejas.android10.sample.domain.repository.UserRepository;
import java.util.Collection;
import javax.inject.Inject;
import javax.inject.Singleton;
/**
* This class is an implementation of {@link GetUserListUseCase} that represents a use case for
* retrieving a collection of all {@link User}.
*/
@Singleton
public class GetUserListUseCaseImpl implements GetUserListUseCase {
private final UserRepository userRepository;
@ -32,6 +35,7 @@ public class GetUserListUseCaseImpl implements GetUserListUseCase {
* @param postExecutionThread {@link PostExecutionThread} used to post updates when the use case
* has been executed.
*/
@Inject
public GetUserListUseCaseImpl(UserRepository userRepository, ThreadExecutor threadExecutor,
PostExecutionThread postExecutionThread) {
if (userRepository == null || threadExecutor == null || postExecutionThread == null) {

View File

@ -39,14 +39,11 @@ public class UserModule {
return userDataRepository;
}
@Provides GetUserListUseCase provideGetUserListUseCase(UserRepository userRepository,
ThreadExecutor threadExecutor, PostExecutionThread postExecutionThread) {
return new GetUserListUseCaseImpl(userRepository, threadExecutor, postExecutionThread);
@Provides GetUserListUseCase provideGetUserListUseCase(GetUserListUseCaseImpl getUserListUseCase) {
return getUserListUseCase;
}
@Provides GetUserDetailsUseCase provideGetUserDetailsUseCase(UserRepository userRepository,
ThreadExecutor threadExecutor, PostExecutionThread postExecutionThread) {
return new GetUserDetailsUseCaseImpl(userRepository,
threadExecutor, postExecutionThread);
@Provides GetUserDetailsUseCase provideGetUserDetailsUseCase(GetUserDetailsUseCaseImpl getUserDetailsUseCase) {
return getUserDetailsUseCase;
}
}