使用原则 2 和存储库,服务层的目的是什么?
我正在设计我的应用程序,并且正在使用 Doctrine 2 和 Zend Framework。
目前,我已经编写了所有实体,我将开始编写存储库,我想到了服务,我想知道我的服务层是否不会重复存储库。
当我使用 Doctrine 2 存储库时,是否值得编写一个服务层?
然而,我到处读到服务层可以用来做缓存。
您有实施示例吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
存储库和服务之间的区别在于,我让我的服务接受数据数组以进行更新、创建等。IIRC,真正的存储库应该只处理域对象。例如,您可以做的另一件事是使用服务层来处理产品缩略图、个人资料图片或缓存等的生成。重点是服务与处理 Doctrine 实体并不严格相关。
我仍然使用自定义存储库作为所有自定义查询的容器;它们在我的服务类中消耗,有时直接在我的控制器中消耗。虽然我使用我的服务进行序列化(用于 JSON 响应)。
仍然有一个小的灰色区域,应该在哪里,你只需要摸索一下。归根结底:如果您忽略服务层并将该逻辑放入存储库中,维护和可扩展性方面的工作量仍然不会增加,只是类责任的定义会减少。
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.
我长期以来一直在寻找合适的(服务层、具有学说 2 和 ZF 的存储库)实现示例。
我发现的这个示例最好,应该对您的工作有帮助
https://github.com/epixa/Forum/tree/master/application /user/src
还有一件事,http://martinfowler.com/eaaCatalog/serviceLayer.html 这将有助于理解服务层的理论部分
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