About repository Mode

Source: Internet
Author: User
Tags to domain

Definition ("Enterprise Application Architecture Model" from Martin Fowler):

Mediates between the domain and data mapping layers using a Collection-like interface for accessing domain objects.

Personal understanding: Repository is a separate layer, between the domain layer and the data mapping layer (the data access layer). Its existence makes the domain layer feel the presence of the data access layer, which provides a similar set of interfaces that provide access to domain objects for domain layers. Repository is the warehouse manager, the domain layer needs to tell the warehouse manager, the warehouse manager to bring things to it, do not need to know where things are actually put.

Tabbycat's Understanding (source):

1. Repository mode is the architecture mode, it has the reference value when designing the architecture;

2. Repository mode is mainly to encapsulate data query and storage logic;

3. Repository mode actual use: Replace, upgrade ORM engine, do not affect business logic;

4. Repository mode can improve the test efficiency, while unit test, the mock object instead of the actual database access, can multiply the test case running speed.

Evaluation: The benefits of applying the repository model are much higher than the code added to implement this pattern. This pattern should be used as long as the project is layered.

About the generic repository Interface (source):

It is not appropriate to use the generic repository interface only, because the repository interface is an operational contract provided to the domain layer, and different entity may have different operational constraints for domain. Therefore, the Repository interface should be defined separately for each eneity class.

The generic repository<t> class is still used to reduce duplicate code, but cannot be inherited directly by the Userrepository class, because the Delete method will invade the user class, so instead in Userrepository Combine a repository<t>, and delegate to this repository<t> the ability to open to domain visible and use generic reuse

The difference between repository and Dal (source):

Repository is the concept of DDD, emphasizing that repository is domain-driven, and that the functions defined in repository embody the intent and constraints of domain, and that the DAL is more purely a function of providing data access, is not strictly restricted to the business layer.

Using Repository, there is a tendency to imply that the domain needs what I provide, not the functionality should not be provided, everything is based on the needs of domain, and the use of the DAL, the intention is that my DAL layer can use the number of The library access operation is provided to the business layer, which is the one you choose for your business. A business can also be used with my dal, and everything is at the core of what my dal can offer.

Related English articles:

Using Repository and Unit of work patterns with Entity Framework 4.0

Implementing Repository Pattern with Entity Framework

Using the Entity Framework Repository and Unitofwork Pattern in C # ASP. NET

Revisiting the Repository and Unit of work Patterns with Entity Framework

Do we need to use the Repository pattern when working in ASP. NET MVC with ORM solutions?

We have IQueryable, so-bother with a repository

Crazy talk:reducing ORM Friction

Recommended code Examples:

Microsoft-domain oriented n-layered. NET 4.0 App Sample (DDD Architecture)

Related blog Posts:

EntityFramework field-driven design Practice (vii)-life cycle of model objects-warehousing

EntityFramework field-driven design practice (eight)-Warehousing implementation: Basic article

About repository Mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.