From a7e4291e4255f04137adc489fb31fa0171edbdf7 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Wed, 16 Apr 2025 09:39:14 +0200 Subject: [PATCH] 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. --- DigitalData.Core.Infrastructure/DbRepository.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/DigitalData.Core.Infrastructure/DbRepository.cs b/DigitalData.Core.Infrastructure/DbRepository.cs index 20c2edb..d79c673 100644 --- a/DigitalData.Core.Infrastructure/DbRepository.cs +++ b/DigitalData.Core.Infrastructure/DbRepository.cs @@ -1,4 +1,5 @@ -using DigitalData.Core.Abstractions.Infrastructure; +using AutoMapper; +using DigitalData.Core.Abstractions.Infrastructure; using Microsoft.EntityFrameworkCore; using System.Linq.Expressions; @@ -6,14 +7,17 @@ namespace DigitalData.Core.Infrastructure; public class DbRepository : IRepository where TDbContext : DbContext where TEntity : class { - protected TDbContext Context; + protected readonly TDbContext Context; - protected DbSet Entities; + protected readonly DbSet Entities; - public DbRepository(TDbContext context, Func> queryFactory) + protected readonly IMapper Mapper; + + public DbRepository(TDbContext context, Func> queryFactory, IMapper mapper) { Context = context; Entities = queryFactory(context); + Mapper = mapper; } public Task CreateAsync(TEntity dto, CancellationToken ct = default)