Need to implement the clean architecture and struggling with DTO concept. As I understand, i can't use my domain objects in presentation layer (asp mvc) instead i should use DTO or viewmodel. I'm not sure where these DTOs should go. I have two projects as my core layer (Domain, Application).Domain holds my entities ex:'Post' + Repository interfaces ex:'IPostRepository' . Application holds logic ex:'IPostManager' + 'PostManager'. Where DTOs and DTOs mapping to Entities should happen ? Asp MVC, Application or Domain?
DTOs are inside Domain Layer... I think it really depends on where you intend to use those DTOs. For example, if the DTOs will mainly used by the frontend that relies on some private APIs then I would put the DTOs into the UI layer as other parts of the system do not need to know about those DTOs.
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 makes sense if you define it there. Don't put your DTO in the Domain Layer.
Short answer: No. Long answer: repository is responsible for turning persisted data back to entities (models) and vice versa.
The layers are the main core of a clean architecture. In our app, we will use three layers: presentation, domain, and model. Each layer should be separated and shouldn't need to know about other layers.
As we already know, Dtos can be of different types that does not have any behaviour and are only used for transporting data eg a Model in the MVC pattern or a class that probably is named with a suffix 'classNameDto'
In your case, it really depends on what context you are using the Application layer. Some Devs understand that 'Application Services' are more specific to the application, meaning they are tied closely to the UI.
If this is the case then, this is a good place to have the Dtos where the data is mapped to and from the domain model.
Else if the mapping is done at the Web layer then Dtos need to go there.
In simple terms as @Jimmy Bogard said "Put the classes close to where they're actually used."
I would also suggest to readup more on the clean architecture and see if you are headed in the right direction.
Hope this helps :)
This looks like a single application. So in that case, I place my DTOs as close to where they are used as possible. If it's MVC, then my DTOs are right next to my views:
Or if it's Razor Pages, then the DTOs are simply inner classes. See my ContosoUniversity examples for a working example:
MVC example
Razor Pages example
It's not "clean architecture" but "vertical slice architecture" but that shouldn't matter. Put the classes close to where they're actually used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With