I wasn't able add a method to wrap existing code in service methods and have that being all you needed to do in order to add caching support... it still required a little refactoring.
However, I did come up with a method to completely replace the existing code which uses a new helper method.
An example is a GET request for a debtor record. The same method can be used for all our maintenance business logic you want to read and serialise out:
- Code: Select all
[Authenticate]
public JiwaFinancials.Jiwa.JiwaServiceModel.Debtors.Debtor Get(DebtorGETRequest request)
{
return Helper.Service.GetDTO<JiwaServiceModel.Debtors.Debtor, JiwaDebtors.Debtor>(this, base.Response, request.DebtorID, (dto) => { return (DateTime)dto.LastSavedDateTime; } );
}
This method simply accepts the generic parameters, the value parameters and it will return any cached DTO if the DTO is registered to be cached, and if there is a DTO present - if not it then it creates the business logic, performs a read and if the DTO is registered to be cached it then adds the DTO to the cache, and adds an optional response header for the Last-Modified (that's the last parameter - a nullable lamda to specify what date to use).
Initially I was worried that this was a level of abstraction which perhaps hid too much, but after comparing with what we had previously and seeing that same dozen or so lines of code repeated over and over in the various GET methods - with just a few type names and values changing - that worry has faded a little.
Similar methods are there for POST, PATCH, DELETE operations and so on - plus overloaded for the different types of business logic (list maintenance, multi-list maintenance, configuration).
It doesn't mean you have to use these helper methods in your own service methods, even if you want to support caching in there - we still have a fairly reasonable way of wrapping that with a few minor tweaks needed to existing code.
It does mean a lot less effort on my part if we decide add more response headers or make logic tweaks - such as adding an ETag - the number of code changes is reduced making that much more manageable.