Difference between repository and service?

前端 未结 3 880
醉话见心
醉话见心 2020-12-12 10:28

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

I\'m talking about data access through a data access layer, typically with linq

相关标签:
3条回答
  • 2020-12-12 10:30

    I would say as a first try, in the general sense (until you give more context if you have one):

    • a repository is where you place some global objects, to be used later.
    • a service is a business logic code, made explicit (and ideally separated from the Presentation layer, and database layer ?)
    0 讨论(0)
  • 2020-12-12 10:49

    The repository is where the data is stored. The service is what manipulates the data.

    In a real-world situation comparison, if your money is stored in a vault in a bank, the vault is the repository. The teller that deposits, withdraws, etc is the service.

    0 讨论(0)
  • 2020-12-12 10:50

    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.

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