use-abp-repositories
Use ABP Repositories
A repository is ABP's abstraction for querying and persisting an aggregate root, provider-independent — the default generic IRepository is implemented by a data-access provider (EF Core, MongoDB, and the in-memory MemoryDb used in tests; the list isn't fixed). (Dapper is not a default-repository provider: ABP's Dapper integration is a custom DapperRepository layered on EF Core for hand-written SQL — see query-with-dapper.) This skill is about consuming an entity's IRepository<TEntity, TKey> — the method surface, eager loading, provider-neutral querying, tracking, and bulk operations. Defining a custom repository interface and its EF Core/MongoDB implementation is a different task — see ef-core-integration / mongodb-integration.
Final application vs. reusable module — pick before you inject. In a final application you can inject and use the default generic IRepository<TEntity, TKey> directly; that's what this skill shows. In a reusable module you publish for others, follow ABP's module best practice instead: define a custom repository interface per aggregate root in the Domain layer, deriving from IBasicRepository<TEntity, TKey> (not the full IRepository), and keep GetQueryableAsync / IQueryable out of the module's public surface — expose only the query methods the module needs. Define that interface + its provider implementation via ef-core-integration / mongodb-integration. The method surface, eager loading, tracking, and bulk guidance below applies to both.
Inject the repository for your aggregate root; the default is registered automatically:
public class BookManager : IDomainService
{
private readonly IRepository<Book, Guid> _bookRepository;
public BookManager(IRepository<Book, Guid> bookRepository) => _bookRepository = bookRepository;
}