Reputation: 47290
Creating a rest-api, my webservice returns either primitives or dto's, and sometimes domain objects. To be precise my controller classes returns those types, after interacting with service classes that return ... ?
Is their a convention for return types from service classes, my understanding is domain objects can be used (and therefore returned) in any layer.
Can dto's/value objects/primitives also be returned ?
Is there a convention for return types within application layers using DDD, and also what if not using DDD ?
(Repositories/DAO's return domain objects/entities or collections of)
Upvotes: 3
Views: 484
Reputation: 8664
I am not sure if there is a convention per say, however here is what we do
Repositories return only aggregates
We have the concept of Finders which denote the read side from
CQRS, they return only DTO's
Domain services return Aggregates or Value Objects typically after
having performed some business logic on either of the above
Application Services return either DTO's (in case of reads) or
Identity (Value Objects) in case of writes
Controllers return DTO's (in case of reads) or Identity (VO) in case of creating something new. Very rarely they return primitives in case the request for only to perform some calculation
Often Controllers use Finders to just return DTO's.
Upvotes: 4