How does the Repository Pattern Differ from a Simple Data Access Layer?

后端 未结 2 337
不思量自难忘°
不思量自难忘° 2021-01-30 22:57

I\'ve been confused by what I\'ve been reading during my research on the repository pattern. I\'m wondering if folks are (incorrectly?) using that word when they simply mean a d

相关标签:
2条回答
  • 2021-01-30 23:56

    Take a look at the "Using the IQueryable interface" section and beyond at Extending and Enhancing the Orders and Registrations Bounded Context. It provides an insightful and balanced discussion of DAO/Repository implementations.

    As subsequently highlighted by Bob Horn, the Persistence Patterns articles summarises that:

    Basically, the Repository pattern just means putting a façade over your persistence system so that you can shield the rest of your application code from having to know how persistence works.

    0 讨论(0)
  • 2021-01-31 00:02

    In general I agree with author's statements, but I'd like to add some details

    Difference between Repository and DAL/ORM that first not only abstracts the persistence mechanism, but also provides collection-like interface for accessing domain objects … and isolates domain objects from details of the database access code:

    Differences

    For external layers, such as Business Logic:

    • Helps to avoid leaky abstraction. External layers depend on abstraction of Repository, rather than a specific implementation of DAL/ORM. Thus you could avoid all infrastructure and logical dependencies while working with Repository.
    • operates with domain objects, rather then a instances of POJO/POCO/DTO
    • CRUD operations applied to collection-like interface provided by Repository, rather then specific DAL/ORM methods. For example .net: working with collection that implements IEnumerable, rather then entity-framework context or nhibernate session

    Similarities

    Repository contains DAL/ORM underneath and serves same purpose

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