Tuesday, December 25, 2018

Entities vs. Repositories in DDD & ASP.NET MVC

Entities vs. Repositories in DDD & ASP.NET MVC

Both Entities and Repositories are defined in DDD separately.
Entities are defined in the Domain Model project.
Interfaces for CustomEntityRepositories are defined in the Domain Model
Repositories are implemented inside their own Data project.
Both have different set of responsibilities.
Entities encapsulate the Domain Logic that is at low level of abstraction
Repositories are responsible to Store the Domain Data Back to the DB.
They are responsible to persist the Domain Data.

Entities  Domain Logic
Repositories  Persistence Logic for Domain Data

When we mention Entity as DBSet Collections inside the DBContext, it gives us Repository Collection for saving and retrieving Entities.

DBContext.Repositories………….Persistence Operations for Entities
Entities………….Domain Logic Operations

Repositories hydrate the Entities. When Entities are hydrated, we can execute Domain Logic against those returned Entities.

REPOSITORES ONLY CONTAIN PERSISTENCE LOGIC; THEY DO NOT CONTAIN DOMAIN LOGIC.


















































No comments:

Post a Comment