Add conditional compilation for .NET Framework support
Updated code to support conditional compilation for .NET Framework and .NET. Introduced nullable reference types in `DbRepository.cs` and ensured proper initialization of service registration queues in `DependencyInjection.cs`. Modified `DbRepositoryFactory.cs` and `DbSetFactory.cs` to maintain consistent structure across frameworks. These changes enhance compatibility and improve type safety.
This commit is contained in:
@@ -4,8 +4,20 @@ using DigitalData.Core.Abstractions.Interfaces;
|
||||
using DigitalData.Core.Infrastructure.Factory;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq.Expressions;
|
||||
#if NETFRAMEWORK
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endif
|
||||
|
||||
namespace DigitalData.Core.Infrastructure;
|
||||
namespace DigitalData.Core.Infrastructure
|
||||
#if NET
|
||||
;
|
||||
#elif NETFRAMEWORK
|
||||
{
|
||||
#endif
|
||||
|
||||
public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbContext : DbContext where TEntity : class
|
||||
{
|
||||
@@ -13,9 +25,17 @@ public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbC
|
||||
|
||||
protected internal readonly DbSet<TEntity> Entities;
|
||||
|
||||
public IMapper? Mapper { get; }
|
||||
public IMapper
|
||||
#if NET
|
||||
?
|
||||
#endif
|
||||
Mapper { get; }
|
||||
|
||||
public DbRepository(TDbContext context, DbSetFactory<TDbContext, TEntity> factory, IMapper? mapper = null)
|
||||
public DbRepository(TDbContext context, DbSetFactory<TDbContext, TEntity> factory, IMapper
|
||||
#if NET
|
||||
?
|
||||
#endif
|
||||
mapper = null)
|
||||
{
|
||||
Context = context;
|
||||
Entities = factory.Create(context);
|
||||
@@ -37,10 +57,19 @@ public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbC
|
||||
return entities;
|
||||
}
|
||||
|
||||
public virtual Task<TEntity> CreateAsync<TDto>(TDto dto, CancellationToken cancel = default) => CreateAsync(Mapper!.Map<TEntity>(dto), cancel);
|
||||
public virtual Task<TEntity> CreateAsync<TDto>(TDto dto, CancellationToken cancel = default)
|
||||
=> CreateAsync(Mapper
|
||||
#if NET
|
||||
!
|
||||
#endif
|
||||
.Map<TEntity>(dto), cancel);
|
||||
|
||||
public virtual Task<IEnumerable<TEntity>> CreateAsync<TDto>(IEnumerable<TDto> dtos, CancellationToken cancel = default)
|
||||
=> CreateAsync(Mapper!.Map<IEnumerable<TEntity>>(dtos), cancel);
|
||||
=> CreateAsync(Mapper
|
||||
#if NET
|
||||
!
|
||||
#endif
|
||||
.Map<IEnumerable<TEntity>>(dtos), cancel);
|
||||
#endregion Create
|
||||
|
||||
#region Read
|
||||
@@ -60,7 +89,11 @@ public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbC
|
||||
|
||||
for (int i = entities.Count - 1; i >= 0; i--)
|
||||
{
|
||||
Mapper!.Map(dto, entities[i]);
|
||||
Mapper
|
||||
#if NET
|
||||
!
|
||||
#endif
|
||||
.Map(dto, entities[i]);
|
||||
Entities.Update(entities[i]);
|
||||
}
|
||||
|
||||
@@ -103,4 +136,8 @@ public class DbRepository : IRepository
|
||||
}
|
||||
|
||||
public IRepository<TEntity> Entity<TEntity>() where TEntity : IEntity => _factory.Get<TEntity>();
|
||||
}
|
||||
}
|
||||
|
||||
#if NETFRAMEWORK
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user