Define the DTO to the layer where the output should come from.
Relative to OP's question: place the DTO in the Domain Service Layer. DTO is an output of that layer, it make sense if you define it there. Don't put your DTO in the Domain Layer. The Domain Layer does not care about things outside of it's layer.
EDIT1 2018: (answer removed, see EDIT2)
EDIT2 2020: Again people seems to be confused with the terminologies. I will now use "Domain Service Layer" as my final answer, relative to OP's question and based on the following layer definitions.
- Presentation Layer (closes to consumer)
- IE: Api
- Has Models or Dto definitions of its own with attributes relative to its layer. IE: If this is an Api then DTO has attributes like formatting or data type validations
- This is the "Application Root" (means that it must reference both Domain Service layer, Data/Infrastructure Layer to be able to inject services)
- Maps data from Domain.Service.Dto to Presentation.Dto
- Domain Service Layer
- Has Dto definitions of its own to be able to return data without exposing the domain entities.
- Services
- Domain Layer
- Domain entities
- May contain Interfaces bridging the infrastructure layer, defined in words that can be understood by the business, free from technical terms (IE: IExcelReport, IGoogleSheetReport, IRepository)
- Data / Infrastructure Layer (closest to your storage of choice)
- Database infrastructure (mapping).
- Excel libraries if you define this layer as infrastructure code.
Some layers have "Application Service Layer" in them to keep the Domain Service Layer pure. You can extend as long as you define the layers properly
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…