I'm designing my application, and I'm using Doctrine 2 and Zend Framework.
Currently, I've wrote all my entities, I was going to start to write Repositories, and I though about Services, and I'm wondering if my Service layer wouldn't repeat the repositories.
Is it worth to write a Service layer while I'm using Doctrine 2 repositories?
However, I read here and there that a Service layer could be used to do caching for example.
Have you any implementation example?
The difference between repositories and services is that I let my services accept arrays of data for updated, creating etc. IIRC, A true repository should only deal with domain objects. Another thing you can do, for example, is use your service layer to handle the generation of thumbnails for products, profile pictures, or caching, etc. The point is that services aren't strictly related to dealing with Doctrine entities.
I still use a custom repositories as a container for all my custom queries and what not; which get consumed in my service classes and occasionally directly in my controllers. Though I use my services for serialising (for JSON responses).
There is still a small grey area with what should be where and you kinda just have to feel it out. At the end of the day: if you leave out there service layer and put that logic into your repositories it still wouldn't be that much more work for maintenance and scalability, just less definition in class responsibility.
I’ve been looking for proper (service layer, repository with doctrine 2 and ZF) implementation example long time.
This example best which i found, should help you in your work
https://github.com/epixa/Forum/tree/master/application/user/src
One more thing, http://martinfowler.com/eaaCatalog/serviceLayer.html this will help to understand theory part of service layer
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