Select Page

The ServiceActionResult pattern

This is not a GOF pattern or anything, but it’s very nice and brings alot to the table.

Basically what I do is this;
Whenever I have some sort of Service/Repository or something similar. Basically any fa├žade where I delegate to CRUD or do CRUD, I return a ServiceActionResult.

The ServiceActionResult class looks like the following:

It’s just a basic generic class that holds a class (T) and an Enum.
The Enum could look something like this, but could be anything you’d like.

It’s kinda like REST.
Return the entity and an HTTP Status code, but instead of a statuscode, we return a ServiceActionStatus

Below you’ll see basic usage:

Using the above. The caller of the CarService just needs to Switch on the ServiceActionStatus and can easily handle, lots of different types of responses.