Repository Pattern Standardization of methods

前端 未结 7 1572
天涯浪人
天涯浪人 2021-01-30 02:05

All I am trying to find out the correct definition of the repository pattern.

My original understanding was this (extremely dumbed down)

  • Separate your Busi
7条回答
  •  日久生厌
    2021-01-30 02:20

    I second the Fowler quote cited by oded. I want to point out that he said "collection-like" interface. How you implement the collection like interface is certainly up to you, but neither can nor should you try to hide the fact it represents a remote datasource. It therefore differs significantly from an in-memory collection, which does not need to flush changes to a remote data store. The change tracking mechanism of your ORM or your roll-your-own solution determines how transparent this can be made to the caller. Deletes usually need to be marked explicitly, inserts are discoverable (persistence by reachability) and updates sometimes need to be marked explicitly too. Combine this with the complicated dependencies of your aggregate roots and you'll see that's not very collection like.

    There is no such thing as "the cannonical repository implementation".

    There is a constant battle going on between the advocators of a generic repository base class and those who prefer implementing each repository on its own. While the generic implementation is appealing in simple scenarios, you will very often find it to be a very leaky abstraction. For example some of your aggregates may only be soft-deleted (cistomizable via virtual method overrides) while others may not support a delete operation at all.

    Make sure you understand the implications of each approach before deciding which route to take. Greg Young has a good post on the merits of generic repositories.

    http://codebetter.com/blogs/gregyoung/archive/2009/01/16/ffffd-the-generic-repository.aspx

提交回复
热议问题