Repository Pattern vs DAL

后端 未结 12 2111
Happy的楠姐
Happy的楠姐 2020-12-02 04:05

Are they the same thing? Just finished to watch Rob Connery\'s Storefront tutorial and they seem to be similar techinques. I mean, when I implement a DAL object I have the G

12条回答
  •  广开言路
    2020-12-02 04:34

    In the external world (i.e. client code) repository is same as DAL, except:

    (1) it's insert/update/delete methods is restricted to have the data container object as the parameter.

    (2) for read operation it may take simple specification like a DAL (for instance GetByPK) or advanced specification.

    Internally it works with a Data Mapper Layer (for instance entity framework context etc) to perform the actual CRUD operation.

    What Repository pattern doesn't mean:-

    Also, I've seen people often get confused to have a separate Save method as the repository pattern sample implementation besides the Insert/Update/Delete methods which commits all the in-memory changes performed by insert/update/delete methods to database. We can have a Save method definitely in a repository, but that is not the responsibility of repository to isolate in-memory CUD (Create, Update, Delete) and persistence methods (that performs the actual write/change operation in database), but the responsibility of Unit Of Work pattern.

    Hope this helps!

提交回复
热议问题