Skip to content

Commit 63caf7a

Browse files
committed
docs: Refactor repositories to return IReadOnlyList<T> results
Updated repository interfaces and implementations to return IReadOnlyList<T> instead of IEnumerable<T> for collection-returning methods. This clarifies intent by indicating returned collections are read-only, reducing risk of unintended modification and improving API expressiveness. Affected methods include GetAll, GetAllAsync, GetActiveProductsAsync, and SearchProductsAsync.
1 parent 5cc3495 commit 63caf7a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ public interface IGenericRepository<TEntity> where TEntity : class
271271
Task CreateAsync(IEnumerable<TEntity> entities, CancellationToken cancellationToken = default);
272272

273273
// Read operations
274-
IEnumerable<TEntity> GetAll(bool ignoreQueryFilters = false, bool trackChanges = false);
275-
Task<IEnumerable<TEntity>> GetAllAsync(bool ignoreQueryFilters = false, bool trackChanges = false, CancellationToken token = default);
274+
IReadOnlyList<TEntity> GetAll(bool ignoreQueryFilters = false, bool trackChanges = false);
275+
Task<IReadOnlyList<TEntity>> GetAllAsync(bool ignoreQueryFilters = false, bool trackChanges = false, CancellationToken token = default);
276276

277277
// Update operations
278278
void Update(TEntity entity);
@@ -436,7 +436,7 @@ public interface IUserRepository : IIdentityRepository<User>
436436

437437
public interface IProductRepository : IIdentityRepository<Product>
438438
{
439-
Task<IEnumerable<Product>> GetActiveProductsAsync(CancellationToken cancellationToken = default);
439+
Task<IReadOnlyList<Product>> GetActiveProductsAsync(CancellationToken cancellationToken = default);
440440
}
441441
```
442442

@@ -457,7 +457,7 @@ public class ProductRepository : IdentityRepository<Product>, IProductRepository
457457
{
458458
public ProductRepository(IDbContext dbContext) : base(dbContext) { }
459459

460-
public async Task<IEnumerable<Product>> GetActiveProductsAsync(CancellationToken cancellationToken = default)
460+
public async Task<IReadOnlyList<Product>> GetActiveProductsAsync(CancellationToken cancellationToken = default)
461461
{
462462
return await GetManyByConditionAsync(p => !p.IsDeleted, token: cancellationToken);
463463
}
@@ -586,7 +586,7 @@ public class ProductService
586586
_productRepository = productRepository;
587587
}
588588

589-
public async Task<IEnumerable<Product>> SearchProductsAsync(string searchTerm, decimal? minPrice = null)
589+
public async Task<IReadOnlyList<Product>> SearchProductsAsync(string searchTerm, decimal? minPrice = null)
590590
{
591591
return await _productRepository.GetManyByConditionAsync(p =>
592592
!p.IsDeleted &&

0 commit comments

Comments
 (0)