Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which layer do functions like: caching and logging belong?

Let's say my business layer currently contains a bunch of DTO's and separate service classes to communicate with the data repository.

Example:

class PersonService
{
   IPersonRepository _personRepository;
   ILogging _logger;
   ICacheStorage _cache;
   // Constructor here to create concrete objects.

   public Person GetPersonById(int Id)
   {
       // error logging and caching here???
   }
}

Does it make sense to log and cache at this layer? Or would it make more sense for an Application Service layer to handle these concerns? Or maybe something else altogether?

like image 642
Mike Avatar asked May 05 '11 13:05

Mike


1 Answers

Caching can or should be implemented whenever possible. Also caching should be transparent, so anyone who uses it shouldn't know it is actualy used. Most of the time it's logical to put it inside a data access layer, but sometimes it is logical and possible to put it in business layer too.

Logging is IMO something, that doesnt belong in any layer. It should be application-wide with one access point.

like image 194
Euphoric Avatar answered Oct 20 '22 01:10

Euphoric