DEV Community


Discussion on: Clean Architecture Essentials

darianbenito profile image
Darian Benito

Hi Ivan, Thanks for share.

What about if we need to obtain all registers from a entity (GetAllEntityXBySomeProperty) to load a DropDownList ? We need to create a UseCase for it, right? Or we just call to the EntityXRepository (GetAllEntityXBySomeProperty method) from the UI ...
Let me shared a personal code:

public class GetAllPropertyTypesByPropertyAgencyUseCase : 
          private readonly IPropertyTypeRepository _propertyTypeRepository;

          public GetAllPropertyTypesByPropertyAgencyUseCase(IPropertyTypeRepository 
             _propertyTypeRepository = propertyTypeRepository;

           public void Execute(GetAllPropertyTypesByPropertyAgencyUseCaseRequest useCaseRequest, 
           IOutputPort<GetAllPropertyTypesByPropertyAgencyUseCaseResponse> outputPort)
              IEnumerable<PropertyType> propertyTypes = 

               if (propertyTypes == default(IEnumerable<PropertyType>))
                  outputPort.HandleError(new List<UseCaseError> { new UseCaseError(1, $" 
                  {nameof(_propertyTypeRepository.GetAllByPropertyAgency)} Not Found") });

                 var getAllByPropertyAgencyPropertyTypeUseCaseResponse = new 

ivanpaulovich profile image
Ivan Paulovich Author

Hey Darian,

Yes, for each interaction you need to create an use case. I implemented an use case similar to yours on Manga Project Checkout the branch "React" for the most up to date code.

BTW your use case implementation is missing a return after outputPort.HandleError. Let me know if you have more questions :)