using Core.Entities; using Core.Interfaces; using Core.Specifications; using Microsoft.EntityFrameworkCore; namespace Infrastructure.Data { public class GenericRepository : IGenericRepository where T : BaseEntity { private readonly StoreContext _context; public GenericRepository(StoreContext context) { _context = context; } public async Task GetByIdAsync(int id) { return await _context.Set().FindAsync(id); } public async Task> ListAllAsync() { return await _context.Set().ToListAsync(); } public async Task GetEntityWithSpec(ISpecification spec) { return await ApplySpecification(spec).FirstOrDefaultAsync(); } public async Task> ListAsync(ISpecification spec) { return await ApplySpecification(spec).ToListAsync(); } private IQueryable ApplySpecification(ISpecification spec) { return SpecificationEvaluator.GetQuery(_context.Set().AsQueryable(), spec); } } }