I've bean reading a lot about DDD lately. I had some basic knowledge (and used it in practice) but now I've decided to go (almost) 100% DDD. Of course I've encountered problems right away.
I got 3 layers for each module (feature): application, domain and infrastructure. I use hexagonal architcture pattern, which basically means that I got my core logic in domain classes, application layer uses it (but domain layer is not aware of application layer at all), infrastructure implements my ports from domain (db repositories) and some interfaces from app layer etc.
Now, when I'm handling some use case in application services I have to work with my root aggregate and perform some logic and finally map it to some DTO for UI. The problem is that to perform such mapping I have to provide getters/setter for most of my attributes which kills me. I want to avoid anemic model by providing a lot of business methods and only very few getters/setters.
I can see 2 solutions:
- introduce DTOs in my domain layer, which is agains DDD, and have methods toDTO() in my entities
- provide getters/setters and use it only in mappers
Any other solutions, how do you people handle such common problem in your apps? I know it's really hard to go purly DDD in reality and it's ok not to follow all the rules but I noticed that having as small number of getters/setters as possible helps me hugely with my design but at the same time it's clear DTO doesnt belong to domain at all.