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

前端 未结 2 1248
渐次进展
渐次进展 2021-02-02 03:13

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 t

相关标签:
2条回答
  • 2021-02-02 04:00

    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.

    0 讨论(0)
  • 2021-02-02 04:15

    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

    0 讨论(0)
提交回复
热议问题