When following the standard service and repository patterns, should your repository contain a specific method for every database operation or should you just use the general methods, e.g. update? Take for example the following service method:
DisableUser(User user) {
user.enabled = false;
userRepo.update(user); // General user update method
}
This performs its changes on the user record, then requests the repo update the database by calling the general user update method.
Or should it be more specific, like:
DisableUser(User user) {
userRepo.disable(user); // Specific operation, matching the service
}
Obviously this is a very simple example but I feel the conclusion affects the way I move forward with repository's in general and this same logic applies to many scenarios.
What further confuses me is that in the first case using the standard update method may be seen as inefficient, because it may update every column on the record, but I happen to be using Entity Framework so it will take care of checking what fields have changed and only updating the changed field for me. But should I be making that assumption from my service?
If I were to write an alternate plain sql implementation of the repository id have to update all fields there, or implement field change detection myself. So that part leans me towards the specific implementation, but with that I'm adding a lot more methods and perhaps it feels a bit unnecessary.
So in a nutshell, should your repo just have the standard methods, update, insert, findById, findAll, delete. Or should it have a method for every specific database operation, like stored procedures.
There's probably several other considerations that I'm not grasping. Any advice would be appreciated.
update(User)is worse than bothdisable(User)(specific, targeted) andupdate(Entity)(generic, reusable).