Enhance DbRepository with AutoMapper integration
Added AutoMapper support by introducing an IMapper field. Changed Context and Entities fields to readonly for better encapsulation. Updated constructor to accept an IMapper parameter, improving object mapping capabilities.
This commit is contained in:
parent
352b59dfdf
commit
a7e4291e42
@ -1,4 +1,5 @@
|
|||||||
using DigitalData.Core.Abstractions.Infrastructure;
|
using AutoMapper;
|
||||||
|
using DigitalData.Core.Abstractions.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
@ -6,14 +7,17 @@ namespace DigitalData.Core.Infrastructure;
|
|||||||
|
|
||||||
public 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 TDbContext Context;
|
protected readonly TDbContext Context;
|
||||||
|
|
||||||
protected DbSet<TEntity> Entities;
|
protected readonly DbSet<TEntity> Entities;
|
||||||
|
|
||||||
public DbRepository(TDbContext context, Func<TDbContext, DbSet<TEntity>> queryFactory)
|
protected readonly IMapper Mapper;
|
||||||
|
|
||||||
|
public DbRepository(TDbContext context, Func<TDbContext, DbSet<TEntity>> queryFactory, IMapper mapper)
|
||||||
{
|
{
|
||||||
Context = context;
|
Context = context;
|
||||||
Entities = queryFactory(context);
|
Entities = queryFactory(context);
|
||||||
|
Mapper = mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<TEntity> CreateAsync(TEntity dto, CancellationToken ct = default)
|
public Task<TEntity> CreateAsync(TEntity dto, CancellationToken ct = default)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user