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

@ -17,9 +17,9 @@
<RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl> <RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl>
<PackAsTool>False</PackAsTool> <PackAsTool>False</PackAsTool>
<PackageIcon>core_icon.png</PackageIcon> <PackageIcon>core_icon.png</PackageIcon>
<Version>3.4.0</Version> <Version>3.4.1</Version>
<AssemblyVersion>3.4.0</AssemblyVersion> <AssemblyVersion>3.4.1</AssemblyVersion>
<FileVersion>3.4.0</FileVersion> <FileVersion>3.4.1</FileVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -5,7 +5,6 @@
/// </summary> /// </summary>
/// <typeparam name="TEntity">The type of the entity this repository works with.</typeparam> /// <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> /// <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> public interface ICRUDRepository<TEntity, TId> where TEntity : class, IUnique<TId>
{ {
/// <summary> /// <summary>

View File

@ -4,13 +4,13 @@ namespace DigitalData.Core.Abstractions.Infrastructure;
public interface IRepository<TEntity> 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);
} }

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net7.0;net8.0;net9.0</TargetFrameworks> <TargetFrameworks>net7.0;net8.0;net9.0</TargetFrameworks>
@ -14,9 +14,9 @@
<PackageIcon>core_icon.png</PackageIcon> <PackageIcon>core_icon.png</PackageIcon>
<RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl> <RepositoryUrl>http://git.dd:3000/AppStd/WebCoreModules.git</RepositoryUrl>
<PackageTags>digital data core application clean architecture</PackageTags> <PackageTags>digital data core application clean architecture</PackageTags>
<Version>3.2.0</Version> <Version>3.2.1</Version>
<AssemblyVersion>3.2.0</AssemblyVersion> <AssemblyVersion>3.2.1</AssemblyVersion>
<FileVersion>3.2.0</FileVersion> <FileVersion>3.2.1</FileVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -5,13 +5,13 @@ using System.Linq.Expressions;
namespace DigitalData.Core.Infrastructure; 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) 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; 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) foreach (var entity in entities)
{ {
throw new NotImplementedException(); entities.Remove(entity);
}
await Context.SaveChangesAsync(ct);
} }
} }

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net7.0;net8.0;net9.0</TargetFrameworks> <TargetFrameworks>net7.0;net8.0;net9.0</TargetFrameworks>
@ -6,7 +6,7 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild> <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageId>DigitalData.Core.Infrastructure</PackageId> <PackageId>DigitalData.Core.Infrastructure</PackageId>
<Version>2.0.0.0</Version> <Version>2.0.1</Version>
<Authors>Digital Data GmbH</Authors> <Authors>Digital Data GmbH</Authors>
<Company>Digital Data GmbH</Company> <Company>Digital Data GmbH</Company>
<Product>DigitalData.Core.Infrastructure</Product> <Product>DigitalData.Core.Infrastructure</Product>