replace IEntityMapper<TEntity> with IMapper
This commit is contained in:
parent
0809d1215b
commit
453a0ccdf0
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user