replace IEntityMapper<TEntity> with IMapper

This commit is contained in:
tekh 2025-09-10 17:33:26 +02:00
parent 0809d1215b
commit 453a0ccdf0
3 changed files with 9 additions and 7 deletions

View File

@ -7,13 +7,13 @@ public static class Extensions
#region Create
public static Task<TEntity> CreateAsync<TEntity, TDto>(this IRepository<TEntity> repository, TDto dto, CancellationToken ct = default)
{
var entity = repository.Mapper.Map(dto);
var entity = repository.Mapper.Map<TEntity>(dto);
return repository.CreateAsync(entity, ct);
}
public static Task<IEnumerable<TEntity>> CreateAsync<TEntity, TDto>(this IRepository<TEntity> repository, IEnumerable<TDto> dtos, CancellationToken ct = default)
{
var entities = dtos.Select(dto => repository.Mapper.Map(dto));
var entities = dtos.Select(dto => repository.Mapper.Map<TEntity>(dto));
return repository.CreateAsync(entities, ct);
}
#endregion

View File

@ -1,10 +1,11 @@
using System.Linq.Expressions;
using AutoMapper;
using System.Linq.Expressions;
namespace DigitalData.Core.Abstraction.Application.Repository;
public interface IRepository<TEntity>
{
public IEntityMapper<TEntity> Mapper { get; }
public IMapper Mapper { get; }
public Task<TEntity> CreateAsync(TEntity entity, CancellationToken cancel = default);

View File

@ -1,4 +1,5 @@
using DigitalData.Core.Abstraction.Application.Repository;
using AutoMapper;
using DigitalData.Core.Abstraction.Application.Repository;
using Microsoft.EntityFrameworkCore;
using System.Linq.Expressions;
@ -10,9 +11,9 @@ public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbC
protected internal readonly DbSet<TEntity> Entities;
public IEntityMapper<TEntity> Mapper { get; }
public IMapper Mapper { get; }
public DbRepository(TDbContext context, Func<TDbContext, DbSet<TEntity>> queryFactory, IEntityMapper<TEntity> mapper)
public DbRepository(TDbContext context, Func<TDbContext, DbSet<TEntity>> queryFactory, IMapper mapper)
{
Context = context;
Entities = queryFactory(context);