inject AM IConfigurationProvider rather than IMapper

This commit is contained in:
Collin Barrett 2018-08-11 20:37:48 -05:00
parent 81ac1270e8
commit c1546d45ce
4 changed files with 15 additions and 12 deletions

View file

@ -12,15 +12,16 @@ namespace FilterLists.Services.FilterList
[UsedImplicitly]
public class FilterListService : Service
{
public FilterListService(FilterListsDbContext dbContext, IMapper mapper) : base(dbContext, mapper)
public FilterListService(FilterListsDbContext dbContext, IConfigurationProvider configurationProvider) :
base(dbContext, configurationProvider)
{
}
public async Task<IEnumerable<ListSummaryDto>> GetAllSummariesAsync() =>
await DbContext.FilterLists.ProjectTo<ListSummaryDto>(Mapper.ConfigurationProvider).ToListAsync();
await DbContext.FilterLists.ProjectTo<ListSummaryDto>(ConfigurationProvider).ToListAsync();
public async Task<ListDetailsDto> GetDetailsAsync(uint id) =>
await DbContext.FilterLists.ProjectTo<ListDetailsDto>(Mapper.ConfigurationProvider)
await DbContext.FilterLists.ProjectTo<ListDetailsDto>(ConfigurationProvider)
.FirstOrDefaultAsync(x => x.Id == id)
.FilterParentListFromMaintainerAdditionalLists();
}

View file

@ -13,18 +13,19 @@ namespace FilterLists.Services.Seed
[UsedImplicitly]
public class SeedService : Service
{
public SeedService(FilterListsDbContext dbContext, IMapper mapper) : base(dbContext, mapper)
public SeedService(FilterListsDbContext dbContext, IConfigurationProvider configurationProvider)
: base(dbContext, configurationProvider)
{
}
public async Task<IEnumerable<TSeedDto>> GetAllAsync<TEntity, TSeedDto>() where TEntity : class =>
await DbContext.Set<TEntity>().ProjectTo<TSeedDto>(Mapper.ConfigurationProvider).ToArrayAsync();
await DbContext.Set<TEntity>().ProjectTo<TSeedDto>(ConfigurationProvider).ToArrayAsync();
public async Task<IEnumerable<TSeedDto>> GetAllAsync<TEntity, TSeedDto>(PropertyInfo primarySort)
where TEntity : class =>
await DbContext.Set<TEntity>()
.OrderBy(x => primarySort.GetValue(x, null))
.ProjectTo<TSeedDto>(Mapper.ConfigurationProvider)
.ProjectTo<TSeedDto>(ConfigurationProvider)
.ToArrayAsync();
public async Task<IEnumerable<TSeedDto>> GetAllAsync<TEntity, TSeedDto>(PropertyInfo primarySort,
@ -32,7 +33,7 @@ public async Task<IEnumerable<TSeedDto>> GetAllAsync<TEntity, TSeedDto>(Property
await DbContext.Set<TEntity>()
.OrderBy(x => primarySort.GetValue(x, null))
.ThenBy(x => secondarySort.GetValue(x, null))
.ProjectTo<TSeedDto>(Mapper.ConfigurationProvider)
.ProjectTo<TSeedDto>(ConfigurationProvider)
.ToArrayAsync();
}
}

View file

@ -7,15 +7,15 @@ namespace FilterLists.Services
[UsedImplicitly]
public class Service
{
protected readonly IConfigurationProvider ConfigurationProvider;
protected readonly FilterListsDbContext DbContext;
protected readonly IMapper Mapper;
public Service(FilterListsDbContext dbContext) => DbContext = dbContext;
public Service(FilterListsDbContext dbContext, IMapper mapper)
public Service(FilterListsDbContext dbContext, IConfigurationProvider configurationProvider)
{
DbContext = dbContext;
Mapper = mapper;
ConfigurationProvider = configurationProvider;
}
}
}

View file

@ -19,7 +19,8 @@ public class SnapshotService : Service
private static readonly IList<uint> IgnoreLists =
new ReadOnlyCollection<uint>(new List<uint> {48, 149, 173, 185, 186, 187, 188, 189, 352});
public SnapshotService(FilterListsDbContext dbContext, IMapper mapper) : base(dbContext, mapper)
public SnapshotService(FilterListsDbContext dbContext, IConfigurationProvider configurationProvider)
: base(dbContext, configurationProvider)
{
}
@ -49,7 +50,7 @@ await DbContext
.ThenBy(list =>
list.Snapshots.Select(ss => ss.CreatedDateUtc).OrderByDescending(sscd => sscd).FirstOrDefault())
.Take(batchSize)
.ProjectTo<FilterListViewUrlDto>(Mapper.ConfigurationProvider)
.ProjectTo<FilterListViewUrlDto>(ConfigurationProvider)
.ToListAsync();
private IEnumerable<SnapshotDe> GetSnapshots(IEnumerable<FilterListViewUrlDto> lists) =>