The dogma of entity-based Services and Repositories
The dogma of entity-based Services and Repositories
Every day I see more projects where a layer-per-entity approach is created by default: UserService, UserRepository, OrderService, OrderRepository, and so on. My issue is not with layering itself, but with how these layers are used.
In theory, a Service should represent application behavior: something that encapsulates real use cases or meaningful interactions with external systems (payments, emails, APIs, etc.). Something with enough significance to justify being isolated.
A Repository, in theory, should exist when there is real complexity in data access: multiple data sources, non-trivial persistence logic, evolving storage mechanisms, etc.
However, in practice, they often degrade into something else:
- Services that simply delegate calls
- Repositories that are thin wrappers around an ORM
- Interfaces with no meaningful alternative implementation
At that point, the abstraction starts to lose its purpose. Why not use the ORM directly when there is no real complexity to hide? Why do we default to intermediate layers that don't truly represent either a service or a repository in their original sense?
It often feels like they add files, indirection, and noise without improving clarity. I'm not saying these layers are inherently bad. I'm trying to understand why they are so often applied by default, even when they don't serve their actual purpose.
Does this approach really improve clarity?
Does this approach really improve clarity, or does it just introduce unnecessary complexity?
For example, instead of organizing code around generic services per model, we could structure it around explicit use cases for concrete system actions. These would still live within an application/service layer in the sense described by Fowler, but without forcing a generic ModelService structure for everything.
The goal would be to design around intent rather than around structural templates-so the code reflects what the system does, not just how it is layered.
Comments
No comments yet. Start the discussion.