Reputation: 21206
When I look at Microsofts sample about the repository pattern its of course a total simple sample nothing to do with the real world requirements - as always...-
The Repository Add/Del/Update methods return Void - nothing -
On the other side when someone uses my RESTful Web API I want to offer things like
NotFound()
if the deletion of a record did not do anything
OK()
If the deletion was successful
Same for Update method.
What do you use in your real world projects as return types for your repositories to let the caller know what really happened?
Upvotes: 3
Views: 1965
Reputation: 151584
What do you use in your real world projects as return types for your repositories to let the caller know what really happened?
A "result object". A simple version could look like this:
public class RepositoryActionResult
{
public int RecordsAffected { get; set; }
}
Then you can set that from your repository methods and handle the results from calling code appropriately, without using exceptions for control flow.
You can make this class as complex as you want, depending on your requirements.
Upvotes: 0
Reputation: 156504
There are two major options:
DeletePerson
to return NotFound if the person itself wasn't there, but if no data is present when you use a different repository to clean up some related data, you want to use a different return type?)What you should avoid is having the Repository layer return some kind of HTTP-oriented response code.
Upvotes: 2