feat(IEntityMapper): Erstellt, um Mapper zu abstrahieren.

- Integriert in IRepository und Repository
This commit is contained in:
Developer 02
2025-04-22 11:10:55 +02:00
parent 85787e7054
commit 5465fe5b49
3 changed files with 41 additions and 7 deletions

View File

@@ -1,5 +1,4 @@
using AutoMapper;
using DigitalData.Core.Abstractions.Infrastructure;
using DigitalData.Core.Abstractions.Infrastructure;
using Microsoft.EntityFrameworkCore;
using System.Linq.Expressions;
@@ -10,10 +9,9 @@ public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbC
protected internal readonly TDbContext Context;
protected internal readonly DbSet<TEntity> Entities;
public IEntityMapper<TEntity> Mapper { get; }
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, IEntityMapper<TEntity> mapper)
{
Context = context;
Entities = queryFactory(context);
@@ -36,13 +34,13 @@ public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbC
public virtual Task<TEntity> CreateAsync<TDto>(TDto dto, CancellationToken ct = default)
{
var entity = Mapper.Map<TEntity>(dto);
var entity = Mapper.Map(dto);
return CreateAsync(entity, ct);
}
public virtual Task<IEnumerable<TEntity>> CreateAsync<TDto>(IEnumerable<TDto> dtos, CancellationToken ct = default)
{
var entities = dtos.Select(dto => Mapper.Map<TEntity>(dto));
var entities = dtos.Select(dto => Mapper.Map(dto));
return CreateAsync(entities, ct);
}