The Repository pattern abstracts data access behind an interface. Generic IRepository<T> over EF Core is usually an anti-pattern: it wraps a unit-of-work (DbContext) in another unit-of-work and leaks IQueryable anyway. Domain repositories (IOrderRepository with business-meaningful queries) earn their keep by hiding persistence complexity. The Specification pattern adds composable query logic without proliferating method overloads.
Each stage in order — click any step to read what it does.
Clean Architecture with domain repository and specification pattern.
The trade-offs worth knowing before you build this.
DbContext IS the unit of work. DbSet<T> IS the repository. Adding IRepository<T, TId> wraps a UoW in a UoW and leaks IQueryable.
IOrderRepository.GetPendingForWarehouse(id) is valuable. IOrderItemRepository is not — access items through the Order aggregate.
Avoid GetByStatus, GetByCustomer, GetByStatusAndCustomer, etc. One Find(ISpecification<Order>) method handles all compositions.
Sign in to share your feedback and join the discussion.