A repository separates the domain model from the data layer by presenting persisted objects and operations through a collection-like interface. It can encapsulate mapping and persistence work, and make data-store dependencies easier to replace in tests. When Entity Framework Core already provides enough abstraction, a repository may be unnecessary. section 7.4.1 section 7.4
A repository interface lets application code request operations without depending directly on the data store. In a customer importer, the importer checks for a customer by email, then creates or updates the customer through that interface. Tests can substitute a fake repository instead of setting up a test database. section 7.4.1 section 7.5
Listing 7.19 ICustomerRepository interface
namespace CustomerBatchImporter;
public interface ICustomerRepository
{
Task CreateAsync( #1
NewCustomerDto customer); #2
Task UpdateAsync(
UpdateCustomerDto customer);
Task<Customer?> GetByEmailAsync(string email); #3
}
public record NewCustomerDto( #4
string Email,
string Name,
string License
) { } #5
public record UpdateCustomerDto(
int Id,
string? NewName,
string? NewLicense
) { }
The customer repository interface shows the create, update, and lookup operations used by the importer. section 7.4.1








