update DbRepository
This commit is contained in:
parent
be96bd0c07
commit
8743325067
@ -1,7 +1,6 @@
|
||||
using AutoMapper;
|
||||
using DigitalData.Core.Abstraction.Application.Repository;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace DigitalData.Core.Infrastructure;
|
||||
@ -35,7 +34,7 @@ public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbC
|
||||
return entities;
|
||||
}
|
||||
|
||||
public IQueryable<TEntity> Where() => Entities.AsQueryable();
|
||||
public IQueryable<TEntity> Where(Expression<Func<TEntity, bool>> expression) => Entities.AsQueryable().Where(expression);
|
||||
|
||||
public IQueryable<TEntity> Get() => Entities.AsNoTracking();
|
||||
|
||||
@ -86,5 +85,5 @@ public class DbRepository : IRepository
|
||||
_factory = factory;
|
||||
}
|
||||
|
||||
public IRepository<TEntity> Entity<TEntity>() => _factory.Get<TEntity>();
|
||||
public IRepository<TEntity> Entity<TEntity>() where TEntity : IEntity => _factory.Get<TEntity>();
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
using DigitalData.Core.Abstraction.Application.Repository;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace DigitalData.Core.Infrastructure;
|
||||
|
||||
public class EntityConfigurationOptions<TEntity>
|
||||
{
|
||||
private readonly IServiceCollection _services;
|
||||
|
||||
public EntityConfigurationOptions(IServiceCollection services)
|
||||
{
|
||||
_services = services;
|
||||
}
|
||||
|
||||
public EntityConfigurationOptions<TEntity> AddCustomMapper<TEntityMapper>(Action<IServiceCollection> configure, Func<IServiceProvider, TEntityMapper>? factory = null)
|
||||
where TEntityMapper : class, IEntityMapper<TEntity>
|
||||
{
|
||||
configure(_services);
|
||||
|
||||
if (factory is null)
|
||||
_services.AddSingleton<IEntityMapper<TEntity>, TEntityMapper>();
|
||||
else
|
||||
_services.AddSingleton(factory);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@ -1,13 +1,13 @@
|
||||
namespace DigitalData.Core.Tests.Infrastructure;
|
||||
|
||||
using DigitalData.Core.Infrastructure;
|
||||
using DigitalData.Core.Tests.Mock;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System.Reflection;
|
||||
using DigitalData.Core.Infrastructure.AutoMapper;
|
||||
using DigitalData.Core.Application.Interfaces.Repository;
|
||||
using DigitalData.Core.Abstraction.Application.Repository;
|
||||
using Bogus.Platform;
|
||||
|
||||
public class DbRepositoryTests
|
||||
{
|
||||
@ -22,7 +22,7 @@ public class DbRepositoryTests
|
||||
|
||||
builder.Services.AddDbContext<MockDbContext>(opt => opt.UseInMemoryDatabase("MockDB"));
|
||||
|
||||
builder.Services.AddDbRepository<MockDbContext, User>(context => context.Users).UseAutoMapper(typeof(UserCreateDto), typeof(UserReadDto), typeof(UserBase));
|
||||
builder.Services.AddDbRepository<MockDbContext>(typeof(User).GetAssembly());
|
||||
|
||||
builder.Services.AddAutoMapper(Assembly.GetExecutingAssembly());
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user