I'm developing a Rest API using Service Stack's framework. All layers are separated so we can make DAL mocks for business logic layer unit testing.
I'm configuring the cache with inversion of control:
container.Register<ICacheClient>(new MemoryCacheClient());
Where MemoryCacheClient
is a simple class that implements ICacheClient
with a few methods.
And here is the question: What is the best layer in which to include the call to the cache through this inversion of control?
It could be in the BLL, but won't it bring problems to unit tests?
It could be in DAL, knowing that I would have to lose IOC? And, in this case, I will depend of webserver's cache, that could be wrong.
It could be in Web interface, knowing that I can have some logic here and even lose some features?
It could be between web interface and BLL, creating a new layer?
I've searched a lot and read some articles, but with no lucky:
Help with debate on Separation of concerns (Data Access vs Business Logic)
http://www.velocityreviews.com/forums/t639532-3-tier-design-and-cache-for-asp-net-3-5-a.html
Thank's
Your caching doesn't need to be in either layer. You can keep it external from your business logic and data access logic by wrapping the calls that would leverage caching in a decorated method and configuring the use of the caching decorator in the IoC container.
I haven't done this using ServiceStack specifically, but the pattern is well documented:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With