Introduce generic IRepository<T> and refactor repositories

Added a generic IRepository<T> interface for common CRUD operations and updated ICatalogRepository to inherit from it, removing redundant methods. Updated CatalogRepository to implement the new interface. Cleaned up DbFirst.Domain.csproj by removing an unused folder reference. These changes improve code reuse and align with clean architecture practices.
This commit is contained in:
OlgunR
2026-01-19 16:36:08 +01:00
parent 6c2b1884d2
commit 166acea8b1
4 changed files with 16 additions and 9 deletions

View File

@@ -6,8 +6,4 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Folder Include="Repositories\" />
</ItemGroup>
</Project> </Project>

View File

@@ -34,12 +34,8 @@ A generic Repository<T> isnt really worthwhile here:
* See: https://github.com/jasontaylordev/CleanArchitecture/blob/main/src/Infrastructure/Identity/IdentityService.cs * See: https://github.com/jasontaylordev/CleanArchitecture/blob/main/src/Infrastructure/Identity/IdentityService.cs
*/ */
public interface ICatalogRepository public interface ICatalogRepository : IRepository<VwmyCatalog>
{ {
Task<List<VwmyCatalog>> GetAllAsync(CancellationToken cancellationToken = default);
Task<VwmyCatalog?> GetByIdAsync(int id, CancellationToken cancellationToken = default);
Task<VwmyCatalog?> GetByTitleAsync(string title, CancellationToken cancellationToken = default); Task<VwmyCatalog?> GetByTitleAsync(string title, CancellationToken cancellationToken = default);
Task<VwmyCatalog> InsertAsync(VwmyCatalog catalog, CancellationToken cancellationToken = default);
Task<VwmyCatalog?> UpdateAsync(int id, VwmyCatalog catalog, CatalogUpdateProcedure procedure, CancellationToken cancellationToken = default); Task<VwmyCatalog?> UpdateAsync(int id, VwmyCatalog catalog, CatalogUpdateProcedure procedure, CancellationToken cancellationToken = default);
Task<bool> DeleteAsync(int id, CancellationToken cancellationToken = default);
} }

View File

@@ -0,0 +1,10 @@
namespace DbFirst.Domain.Repositories;
public interface IRepository<T>
{
Task<List<T>> GetAllAsync(CancellationToken cancellationToken = default);
Task<T?> GetByIdAsync(int id, CancellationToken cancellationToken = default);
Task<T> InsertAsync(T entity, CancellationToken cancellationToken = default);
Task<T?> UpdateAsync(int id, T entity, CancellationToken cancellationToken = default);
Task<bool> DeleteAsync(int id, CancellationToken cancellationToken = default);
}

View File

@@ -107,6 +107,11 @@ public class CatalogRepository : ICatalogRepository
return await _db.VwmyCatalogs.AsNoTracking().FirstOrDefaultAsync(x => x.Guid == guid, cancellationToken); return await _db.VwmyCatalogs.AsNoTracking().FirstOrDefaultAsync(x => x.Guid == guid, cancellationToken);
} }
public async Task<VwmyCatalog?> UpdateAsync(int id, VwmyCatalog catalog, CancellationToken cancellationToken = default)
{
return await UpdateAsync(id, catalog, CatalogUpdateProcedure.Update, cancellationToken);
}
public async Task<bool> DeleteAsync(int id, CancellationToken cancellationToken = default) public async Task<bool> DeleteAsync(int id, CancellationToken cancellationToken = default)
{ {
var exists = await _db.VwmyCatalogs.AsNoTracking().AnyAsync(x => x.Guid == id, cancellationToken); var exists = await _db.VwmyCatalogs.AsNoTracking().AnyAsync(x => x.Guid == id, cancellationToken);