DDD — which layer DTO should be implemented?

Define the DTO to the layer where the source of the values comes from.

Relative to OP’s question: place the DTO in the Application 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 mapping things to serve external layers (the domain does not know there is a world outside of its own)

Presentation Layer (closes to consumers)

  • This could be your Api
  • Has Models or Dto definitions of its own with attributes relative to its layer. If this is an Api then Models/DTO has attributes for 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 between ApplicationService.Dto and Presentation.Dto

Application Service Layer

  • Has Dto definitions of its own to be able to return data without exposing the domain entities.
  • Bridge between Presentation Layer and Domain Layer.
  • Contains Application Services. See answer for detailed definition ofApplication 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)
  • May contain «Domain Services»

Data / Infrastructure Layer (closest to your database or external services)

  • Database infrastructure (mapping).
  • Excel libraries if you define this layer as infrastructure code.
  • Mail or notification services.
  • PDF output files
admin

Recent Posts

После включения диагностического запуска не удается войти в Windows — как исправить?

Некоторые пользователи, экспериментируя с конфигурацией системы в окне msconfig могут столкнуться с ситуацией, когда после…

2 недели ago

WinScript — очистка и настройка Windows 11 и 10

На сайте не раз публиковались обзоры программ, предназначенных для очистки или настройки последних версий Windows.…

2 недели ago

Предварительный просмотр накопительного обновления не устанавливается — решение

При установке некоторых обновлений Windows 11, имеющих в названии «Предварительный просмотр накопительного обновления», многие пользователи…

2 недели ago

FixExec — восстановление ассоциаций .exe, .bat и .com файлов

Некоторые пользователи Windows 11, 10 и предыдущих версий системы могут столкнуться с ситуацией, когда исполняемые…

2 недели ago

Ошибка 0x800705b4 при обновлении Windows 11 и 10 — как исправить?

При установке обновлений Windows 11/10 некоторые пользователи могут столкнуться с ошибкой с кодом 0x800705b4 и…

2 недели ago

Обслуживание вашей версии Windows 11 окончено — что делать?

Пользователи Windows 11 могут столкнуться с сообщением «Обслуживание вашей версии Windows окончено» (Your version of…

2 недели ago