Bump version numbers and enhance repository interfaces

- Incremented version numbers in project files for updates.
- Marked `ICRUDRepository` as obsolete; use `IRepository` instead.
- Improved parameter names and signatures in `IRepository`.
- Changed access modifiers in `DbRepository` for broader access.
- Updated `CreateAsync` and `UpdateAsync` methods for async operations.
- Implemented `ReadAsync` and `DeleteAsync` methods in `DbRepository`.
- Minor whitespace change in `.csproj` files.
- Retained package description in `DigitalData.Core.Infrastructure.csproj`.
This commit is contained in:
Developer 02
2025-04-17 12:53:40 +02:00
parent 5427a9722d
commit 0c529b199b
6 changed files with 49 additions and 31 deletions

View File

@@ -5,13 +5,13 @@ using System.Linq.Expressions;
namespace DigitalData.Core.Infrastructure;
internal class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbContext : DbContext where TEntity : class
public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbContext : DbContext where TEntity : class
{
protected readonly TDbContext Context;
protected internal readonly TDbContext Context;
protected readonly DbSet<TEntity> Entities;
protected internal readonly DbSet<TEntity> Entities;
protected readonly IMapper Mapper;
protected internal readonly IMapper Mapper;
public DbRepository(TDbContext context, Func<TDbContext, DbSet<TEntity>> queryFactory, IMapper mapper)
{
@@ -20,28 +20,47 @@ internal class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TD
Mapper = mapper;
}
public virtual Task<TEntity> CreateAsync(TEntity entity, CancellationToken ct = default)
public virtual async Task<TEntity> CreateAsync(TEntity entity, CancellationToken ct = default)
{
throw new NotImplementedException();
Entities.Add(entity);
await Context.SaveChangesAsync(ct);
return entity;
}
public virtual Task<TEntity> CreateAsync(IEnumerable<TEntity> entities, CancellationToken ct = default)
public virtual async Task<IEnumerable<TEntity>> CreateAsync(IEnumerable<TEntity> entities, CancellationToken ct = default)
{
throw new NotImplementedException();
Entities.AddRange(entities);
await Context.SaveChangesAsync(ct);
return entities;
}
public virtual Task<IEnumerable<TEntity>> DeleteAsync<TDto>(Expression expression, CancellationToken ct = default)
public virtual async Task<IEnumerable<TEntity>> ReadAsync(Expression<Func<TEntity, bool>>? expression = null, CancellationToken ct = default)
=> expression is null
? await Entities.AsNoTracking().ToListAsync(ct)
: await Entities.AsNoTracking().Where(expression).ToListAsync(ct);
public virtual async Task UpdateAsync<TUpdate>(TUpdate update, Expression<Func<TEntity, bool>> expression, CancellationToken ct = default)
{
throw new NotImplementedException();
var entities = await Entities.Where(expression).ToListAsync(ct);
foreach (var entity in entities)
{
Mapper.Map(update, entity);
Entities.Add(entity);
}
await Context.SaveChangesAsync(ct);
}
public virtual Task<IEnumerable<TEntity>> ReadAsync(Expression? expression = null, CancellationToken ct = default)
public virtual async Task DeleteAsync<TDto>(Expression<Func<TEntity, bool>> expression, CancellationToken ct = default)
{
throw new NotImplementedException();
}
var entities = await Entities.Where(expression).ToListAsync(ct);
public virtual Task<IEnumerable<TEntity>> UpdateAsync<TDto>(TDto dto, Expression expression, CancellationToken ct = default)
{
throw new NotImplementedException();
foreach (var entity in entities)
{
entities.Remove(entity);
}
await Context.SaveChangesAsync(ct);
}
}