Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Doctrine 2 and Repositories, what would be the purpose of a Service Layer?

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?

like image 762
JohnT Avatar asked Apr 29 '11 21:04

JohnT


2 Answers

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.

like image 183
Cobby Avatar answered Sep 22 '22 19:09

Cobby


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

like image 37
Nikolai Senkevich Avatar answered Sep 22 '22 19:09

Nikolai Senkevich