feat: Verbesserung von IRepository mit neuen asynchronen Methoden und Erweiterungen
Aktualisiert IRepository<TEntity> um UpdateAsync<TDto>, DeleteAsync<TDto> und eine neue Überladung von ReadAsync. Die frühere ReadAsync-Überladung für Core.Tests.Mock.User wurde entfernt. Einführung einer neuen Extensions-Klasse mit Methoden für ReadFirstOrDefaultAsync, ReadFirstAsync, ReadSingleOrDefaultAsync und ReadSingleAsync unter Nutzung der aktualisierten ReadAsync-Methode.
This commit is contained in:
parent
9376fcff86
commit
476c86ff0a
18
DigitalData.Core.Abstractions/Infrastructure/Extensions.cs
Normal file
18
DigitalData.Core.Abstractions/Infrastructure/Extensions.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace DigitalData.Core.Abstractions.Infrastructure;
|
||||
|
||||
public static class Extensions
|
||||
{
|
||||
public static async Task<TEntity?> ReadFirstOrDefaultAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null)
|
||||
=> (await repository.ReadAsync(expression)).FirstOrDefault();
|
||||
|
||||
public static async Task<TEntity> ReadFirstAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null)
|
||||
=> (await repository.ReadAsync(expression)).First();
|
||||
|
||||
public static async Task<TEntity?> ReadSingleOrDefaultAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null)
|
||||
=> (await repository.ReadAsync(expression)).SingleOrDefault();
|
||||
|
||||
public static async Task<TEntity> ReadSingleAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null)
|
||||
=> (await repository.ReadAsync(expression)).Single();
|
||||
}
|
||||
@ -17,5 +17,4 @@ public interface IRepository<TEntity>
|
||||
public Task UpdateAsync<TDto>(TDto dto, Expression<Func<TEntity, bool>> expression, CancellationToken ct = default);
|
||||
|
||||
public Task DeleteAsync<TDto>(Expression<Func<TEntity, bool>> expression, CancellationToken ct = default);
|
||||
Task ReadAsync(Core.Tests.Mock.User user);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user