From 4526ba189a1d65c2fcd8fbf74353cc2c76589121 Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 12 Sep 2025 12:40:22 +0200 Subject: [PATCH] refactor(DbRepository): make Mapper nullable to be able to use without adding automapper --- DigitalData.Core.Infrastructure/DbRepository.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/DigitalData.Core.Infrastructure/DbRepository.cs b/DigitalData.Core.Infrastructure/DbRepository.cs index 419ffc8..0fece54 100644 --- a/DigitalData.Core.Infrastructure/DbRepository.cs +++ b/DigitalData.Core.Infrastructure/DbRepository.cs @@ -12,9 +12,9 @@ public class DbRepository : IRepository where TDbC protected internal readonly DbSet Entities; - public IMapper Mapper { get; } + public IMapper? Mapper { get; } - public DbRepository(TDbContext context, DbSetFactory factory, IMapper mapper) + public DbRepository(TDbContext context, DbSetFactory factory, IMapper? mapper = null) { Context = context; Entities = factory.Create(context); @@ -35,10 +35,10 @@ public class DbRepository : IRepository where TDbC return entities; } - public Task CreateAsync(TDto dto, CancellationToken cancel = default) => CreateAsync(Mapper.Map(dto), cancel); + public Task CreateAsync(TDto dto, CancellationToken cancel = default) => CreateAsync(Mapper!.Map(dto), cancel); public Task> CreateAsync(IEnumerable dtos, CancellationToken cancel = default) - => CreateAsync(Mapper.Map>(dtos), cancel); + => CreateAsync(Mapper!.Map>(dtos), cancel); public IQueryable Where(Expression> expression) => Entities.AsNoTracking().Where(expression); @@ -54,7 +54,7 @@ public class DbRepository : IRepository where TDbC for (int i = entities.Count - 1; i >= 0; i--) { - Mapper.Map(dto, entities[i]); + Mapper!.Map(dto, entities[i]); Entities.Update(entities[i]); }