存储库与服务的区别? [英] Difference between repository and service?

查看:113
本文介绍了存储库与服务的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

存储库和服务有什么区别?我似乎没有把握它。

What's the difference between a repository and a service? I don't seem to grasp it.

我正在谈论通过数据访问层访问数据,通常使用LINQ to sql。

I'm talking about data access through a data access layer, typically with linq to sql.

我经常使用简单的CRUD方法和具有更多业务特定方法的服务来查看存储库。

Very often i see repositories with simple CRUD methods, and services with more business-specific methods.

我们可以将这个博客帖子为例。如果你看底部的接口(图像),他有两个存储库和两个服务。如何知道要放在哪里?

We can take this blog post as an example. If you look at the interfaces at the bottom (images), he has two repositories and two services. How do one know what to put where?

正如我所说,存储库似乎更适合于CRUD类操作和服务,面向更多的业务。

As i said, repositories seems to be more for CRUD-like operations and Services more business oriented.

谢谢

推荐答案

存储库基本上是一个用于持久化的外观它使用集合样式语义(添加,更新,删除)来提供对数据/对象的访问。这是一种将数据/对象与其他应用程序进行存储的方式相分离的方式。

A Repository is essentially a facade for persistence that uses Collection style semantics (Add, Update, Remove) to supply access to data/objects. It is a way of decoupling the way you store data/objects from the rest of the application.

服务提供协调或其他服务应用。它们是非常不同的,因为服务通常不知道如何从持久性访问数据,而通常只有的存储库访问您可能拥有的任何服务的数据/对象。

A service supplies coordination or other "services" that are required to operate your application. They are very different in that Services don't typically know how to access data from persistence, and repositories typically only access data/objects for any services you may have.

这篇关于存储库与服务的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆