SVR(service, validator & repository) is a lightweight CRUD Service pattern.
The idea is to have an easy to understand, flexible, testable pattern that follows the single responsibility principle.
The service is the main access point. You can look at it as the main API. It's responsibility is to orchestrate the behaviour between the validator, repository and other resources/services.
The validator is used for doing all the validation. It should not have any side effects.
The repository is the data layer. It's role is to get, add, update and delete data.
To prevent circular dependencies and to keep the code DRY. It is important to follow these dependency rules.
Service | Can depend on Validator & Repository |
Validator | Can depend on Repository |
Repository | Can depend on None |
By having orchestration, validation and CRUD operations separated in differnet classes makes each class much easier to test since you only have to focus on one thing when testing each class.