Production-ready GenericRepository and UnitOfWork implementations for EF Core. Features: 50+ methods, Specification Pattern, Soft Delete, Batch Operations, Pagination, AsNoTracking, and Aggregates.
$ dotnet add package Jezda.Common.DataProduction-ready implementations of Repository Pattern, Unit of Work, and Specification Pattern for Entity Framework Core.
dotnet add package Jezda.Common.Data
A comprehensive repository implementation with 50+ methods:
// 1. Create repository
public class ProductRepository : GenericRepository<Product>
{
public ProductRepository(AppDbContext context) : base(context) { }
}
// 2. Register in DI
builder.Services.AddScoped<IUnitOfWork<AppDbContext>, UnitOfWork<AppDbContext>>();
builder.Services.AddScoped<IGenericRepository<Product>, ProductRepository>();
// 3. Use in services
public class ProductService
{
private readonly IUnitOfWork<AppDbContext> _unitOfWork;
private readonly IGenericRepository<Product> _repository;
public async Task<Product> CreateAsync(Product product)
{
_repository.Add(product);
await _unitOfWork.SaveChangesAsync();
return product;
}
public async Task<PagedList<Product>> GetPagedAsync(PagingInfo paging)
{
return await _repository.GetPagedItemsAsync(paging);
}
}
public class ActiveProductsSpec : BaseSpecification<Product>
{
public ActiveProductsSpec(decimal minPrice)
: base(x => x.IsActive && x.Price >= minPrice)
{
AddInclude(x => x.Category);
ApplyOrderBy(x => x.Name);
ApplyAsNoTracking();
}
}
var products = await _repository.GetBySpecAsync(new ActiveProductsSpec(100m));
// Bulk delete
await _repository.DeleteWhereAsync(x => x.IsActive == false);
// Bulk update
await _repository.UpdateWhereAsync(
where: x => x.CategoryId == oldId,
setters: s => s.SetProperty(p => p.CategoryId, newId)
);
var product = await _repository.GetByIdAsync(1);
_repository.SoftDelete(product);
await _unitOfWork.SaveChangesAsync();
// Product.IsDeleted = true
For complete documentation with examples, see the main repository README.
MIT License - see LICENSE for details.