Implementing repositories
To remember the definition, a repository is a collection-like interface used to access the domain objects stored in the data persistence system. It hides the complexity of data access logic behind a simple abstraction.
There are some main rules for implementing repositories:
- Repository interfaces are defined in the domain layer, so the domain and application layers can use them. They are implemented in the infrastructure (or database provider integration) layer.
- Repositories are created for aggregate root entities but not for sub-collection entities. That is because the sub-collection entities should be accessed over the aggregate root. Typically, you have a repository for each aggregate root.
- Repositories work with domain objects, not DTOs.
- In an ideal design, repository interfaces should be independent of the database provider. So, do not get or return EF Core objects, such as
DbContext
orDbSet
. - Do not implement business logic...