1
votes

I am reading Domain Driven Desing these days. Applications are C# programming. So I am a bit confused about Data Transfer Objects between layers.

  • Daoman Layer (includes domain objects)
  • Service Layer
  • Data Layer (Entity Framework)
  • Web UI

Why I need create DTOs for these layers? Which layer include DTOs, each layers inclue own DTO?

2

2 Answers

1
votes

DTOs as the name implies are objects which just transport data. They don't belong to any particular layer, it's a way to communicate data from one layer or context to another. You're using DTOs so that you don't use that context's objects, which models context specific concepts. This way, one layer isn't coupled to another and their model isn't exposed (because a layer's/context model doesn't have meaning outside that context).

0
votes

This question is going to get closed pretty quickly (too broad and subjective), and probably should be asked in the Programmers exchange. But, I can tell you what we do. All of our DTO objects get created at the data layer. All mapping to and from is at that layer. All code above the data layer uses the DTO objects. This has worked best for us after many different alternatives and failures.