I am integrating Zend Framework and Doctrine 2, and I am discovering the Service layer.
Now I understand (am I wrong ?) that I have 2 architectures possible :
What are the pros/cons of each ?
It seems weird to me to lose OOP by putting domain logic as external to the model, so I don't understand why use a Service layer.
What makes you think your Service Layer is external to your model? It isn't. In fact, it's a central part of your model, along with entities, repositories, etc.
If you're using Doctine2, you'll want a service layer. One reason is that you don't want your Entities knowing about the EntityManager (hurts testability). Another is that you also don't want your controllers driving the EM (it's not the controllers job to know about persistence).
I typically use an architecture where the service layer is the controller's interface to the model. The service layer exposes functions that operate on entities (either taking them as parameters, or returning them, or both). Persistence of entities is hidden by the service layer. Either the service class drives the EM and repositories itself, or delegates it to some other code that the controller will never know exists.
So the service layer provides and API that controllers can to use to manipulate your business data.
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