Repository interfaces returning DTO in clean architecture used by query handlers

Repository interfaces are often defined in the Domain layer. This makes sense for command handlers, which call repository methods and return nothing. But what about query handlers that call repository methods which return DTOs instead of domain objects? Query handlers call repository methods that should return DTOs. However, DTOs belong to the Application layer, not the Domain layer. This means that repository interfaces for query handlers cannot be in the Domain layer, because the Domain layer does not have access to DTOs, which exist in the Application layer. Does this mean that repository interfaces for query handlers should be in the Application layer?

Feb 28, 2025 - 18:25
 0
Repository interfaces returning DTO in clean architecture used by query handlers

Repository interfaces are often defined in the Domain layer. This makes sense for command handlers, which call repository methods and return nothing. But what about query handlers that call repository methods which return DTOs instead of domain objects?

Query handlers call repository methods that should return DTOs. However, DTOs belong to the Application layer, not the Domain layer. This means that repository interfaces for query handlers cannot be in the Domain layer, because the Domain layer does not have access to DTOs, which exist in the Application layer.

Does this mean that repository interfaces for query handlers should be in the Application layer?