Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CRUD in DDD Application Services?

I'm new to DDD, but I'm trying to incorporate DDD concepts into my current project.

For many entities in my domain, clients need to perform all of the standard CRUD operations independent of any particular work flow. I'm finding myself with a number of Application-level services with names like UserService or LocationService that do little more than act as facades to the respective repositories.

Are these application-services as repository facades a "correct" application of the application service pattern? Or should CRUD-only methods stay out of application services? If so, should there be a repository facade at the Interface layer?

like image 771
HolySamosa Avatar asked Apr 25 '12 22:04

HolySamosa


1 Answers

This of course depends on the application and can also be a matter of taste where some opt for a more direct approach and expose the repository directly to clients. One benefit of this approach is simplicity. You're not traversing layers to trace the execution of code. On the other hand, a role of the application service is that of a facade or API for the domain layer.

In other words, application services encapsulates the domain layer and orchestrate the execution of domain logic. By this token, the repository can also be encapsulated by the application service. The benefit in this case can be consistency in that all clients of the domain layer interact with it through application services, whether they are issuing commands or retrieving data.

The best solution depends on your application. If all of the required functionality is CRUD or mostly CRUD, there is no need for an application service, (or full-fledged DDD for that matter) because in this case all the service does is delegate to repositories and therefore adds needless complexity. However, the application service can also be a convenient junction for managing transactions and units of work, which the repository shouldn't have to handle.

An alternative is to delegate this responsibility to the infrastructure of the hosting environment, such as action filters in an ASP.NET MVC application.


like image 125
eulerfx Avatar answered Sep 23 '22 20:09

eulerfx