I read in many books that in a layered architecture a layer should only use the services provided by the layers below it. The commonly used layers are in an enterprise application are:
- Presentation
- Business
- Persistence
This means services at business layer (that contain business logic) should access only access the services provided by the persistence layer.
I have a MessageService that sends messages to the users. Whenever there is a significant change in the state of an object, all the associated users must be notified about the change. This means that the Service at business layer that identified the change must send use MessageService to send messages. But messageService is itself at the business layer, hence no other service from the same layer should access it.
So how can we use MessageService without violating the architecture of the code?