Is it Ok if Domain Object cross Service-Boundary?
Everyone recommend that only DTO should be returned by Services.
I am creating simple CRUD application.
Is it ok if my service methods return Domain object instead of flat DTO objects.
It will save me from lots of mapping related setup. Is there any alternative approach?
2
Martin Fowler states the first rule of distributed object design is: Don’t distribute your objects!
It’s understandable that you don’t want to write mapping code to map from Domain to DTO and vice versa. Especially, because initially their data might be same. But doing so you couple the domain model to all the clients of the service. Changing your domain becomes impossible without breaking all the clients.
In .NET there is a library called AutoMapper to help mapping between objects. Other languages probably have similar tools.
1