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:
parent
5427a9722d
commit
0c529b199b
@ -17,9 +17,9 @@
|
||||
<RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl>
|
||||
<PackAsTool>False</PackAsTool>
|
||||
<PackageIcon>core_icon.png</PackageIcon>
|
||||
<Version>3.4.0</Version>
|
||||
<AssemblyVersion>3.4.0</AssemblyVersion>
|
||||
<FileVersion>3.4.0</FileVersion>
|
||||
<Version>3.4.1</Version>
|
||||
<AssemblyVersion>3.4.1</AssemblyVersion>
|
||||
<FileVersion>3.4.1</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
/// </summary>
|
||||
/// <typeparam name="TEntity">The type of the entity this repository works with.</typeparam>
|
||||
/// <typeparam name="TId">The type of the identifier for the entity.</typeparam>
|
||||
[Obsolete("ICRUDRepository has been deprecated. Please use the IRepository interface instead, which provides a better abtraction (e.g. without tracking) and flexibility.")]
|
||||
public interface ICRUDRepository<TEntity, TId> where TEntity : class, IUnique<TId>
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@ -4,13 +4,13 @@ namespace DigitalData.Core.Abstractions.Infrastructure;
|
||||
|
||||
public interface IRepository<TEntity>
|
||||
{
|
||||
public Task<TEntity> CreateAsync(TEntity dto, CancellationToken ct = default);
|
||||
public Task<TEntity> CreateAsync(TEntity entity, CancellationToken ct = default);
|
||||
|
||||
public Task<TEntity> CreateAsync(IEnumerable<TEntity> dtos, CancellationToken ct = default);
|
||||
public Task<IEnumerable<TEntity>> CreateAsync(IEnumerable<TEntity> entities, CancellationToken ct = default);
|
||||
|
||||
public Task<IEnumerable<TEntity>> ReadAsync(Expression? expression = null, CancellationToken ct = default);
|
||||
public Task<IEnumerable<TEntity>> ReadAsync(Expression<Func<TEntity, bool>>? expression = null, CancellationToken ct = default);
|
||||
|
||||
public Task<IEnumerable<TEntity>> UpdateAsync<TDto>(TDto dto, Expression expression, CancellationToken ct = default);
|
||||
public Task UpdateAsync<TUpdate>(TUpdate update, Expression<Func<TEntity, bool>> expression, CancellationToken ct = default);
|
||||
|
||||
public Task<IEnumerable<TEntity>> DeleteAsync<TDto>(Expression expression, CancellationToken ct = default);
|
||||
public Task DeleteAsync<TDto>(Expression<Func<TEntity, bool>> expression, CancellationToken ct = default);
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net7.0;net8.0;net9.0</TargetFrameworks>
|
||||
@ -14,9 +14,9 @@
|
||||
<PackageIcon>core_icon.png</PackageIcon>
|
||||
<RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl>
|
||||
<PackageTags>digital data core application clean architecture</PackageTags>
|
||||
<Version>3.2.0</Version>
|
||||
<AssemblyVersion>3.2.0</AssemblyVersion>
|
||||
<FileVersion>3.2.0</FileVersion>
|
||||
<Version>3.2.1</Version>
|
||||
<AssemblyVersion>3.2.1</AssemblyVersion>
|
||||
<FileVersion>3.2.1</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
public virtual Task<IEnumerable<TEntity>> ReadAsync(Expression? expression = null, CancellationToken ct = default)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
await Context.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
public virtual Task<IEnumerable<TEntity>> UpdateAsync<TDto>(TDto dto, Expression expression, 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);
|
||||
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
entities.Remove(entity);
|
||||
}
|
||||
|
||||
await Context.SaveChangesAsync(ct);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net7.0;net8.0;net9.0</TargetFrameworks>
|
||||
@ -6,7 +6,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<PackageId>DigitalData.Core.Infrastructure</PackageId>
|
||||
<Version>2.0.0.0</Version>
|
||||
<Version>2.0.1</Version>
|
||||
<Authors>Digital Data GmbH</Authors>
|
||||
<Company>Digital Data GmbH</Company>
|
||||
<Product>DigitalData.Core.Infrastructure</Product>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user