update automapper DI nuget

This commit is contained in:
Collin Barrett 2018-08-04 17:18:21 -05:00
parent 16714f56ad
commit c080673fc1
6 changed files with 25 additions and 16 deletions

View file

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using FilterLists.Data;
using JetBrains.Annotations;
@ -12,9 +13,8 @@ namespace FilterLists.Services.FilterList
[UsedImplicitly]
public class FilterListService : Service
{
public FilterListService(FilterListsDbContext dbContext) : base(dbContext)
public FilterListService(FilterListsDbContext dbContext, IMapper mapper) : base(dbContext, mapper)
{
DbContext = dbContext;
}
public async Task<IEnumerable<ListSummaryDto>> GetAllSummariesAsync()
@ -39,7 +39,9 @@ public async Task<IEnumerable<ListSummaryDto>> GetAllSummariesAsync()
}
private async Task<List<ListSummaryDto>> GetSummaryDtos() =>
await DbContext.FilterLists.OrderBy(l => l.Name).ProjectTo<ListSummaryDto>().ToListAsync();
await DbContext.FilterLists.OrderBy(l => l.Name)
.ProjectTo<ListSummaryDto>(Mapper.ConfigurationProvider)
.ToListAsync();
private async Task<List<Data.Entities.Snapshot>> GetLatestSnapshots()
{
@ -53,7 +55,7 @@ private async Task<List<ListSummaryDto>> GetSummaryDtos() =>
public async Task<ListDetailsDto> GetDetailsAsync(uint id)
{
var details = await DbContext.FilterLists.ProjectTo<ListDetailsDto>()
var details = await DbContext.FilterLists.ProjectTo<ListDetailsDto>(Mapper.ConfigurationProvider)
.FirstAsync(x => x.Id == id)
.FilterParentListFromMaintainerAdditionalLists();
details.RuleCount = await GetActiveRuleCount(details);

View file

@ -16,7 +16,7 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="7.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="4.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="5.0.1" />
<PackageReference Include="JetBrains.Annotations" Version="2018.2.1" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.3.0" />
<PackageReference Include="Microsoft.DotNet.Analyzers.Compatibility" Version="0.2.12-alpha" />

View file

@ -10,7 +10,6 @@ public class RuleService : Service
{
public RuleService(FilterListsDbContext dbContext) : base(dbContext)
{
DbContext = dbContext;
}
public async Task<int> GetCountAll() => await DbContext

View file

@ -2,6 +2,7 @@
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using FilterLists.Data;
using JetBrains.Annotations;
@ -12,18 +13,17 @@ namespace FilterLists.Services.Seed
[UsedImplicitly]
public class SeedService : Service
{
public SeedService(FilterListsDbContext dbContext) : base(dbContext)
public SeedService(FilterListsDbContext dbContext, IMapper mapper) : base(dbContext, mapper)
{
DbContext = dbContext;
}
public async Task<IEnumerable<TSeedDto>> GetAllAsync<TEntity, TSeedDto>() where TEntity : class =>
await DbContext.Set<TEntity>().ProjectTo<TSeedDto>().ToArrayAsync();
await DbContext.Set<TEntity>().ProjectTo<TSeedDto>(Mapper.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>()
.ProjectTo<TSeedDto>(Mapper.ConfigurationProvider)
.ToArrayAsync();
public async Task<IEnumerable<TSeedDto>>
@ -31,7 +31,7 @@ public async Task<IEnumerable<TSeedDto>>
where TEntity : class => await DbContext.Set<TEntity>()
.OrderBy(x => primarySort.GetValue(x, null))
.ThenBy(x => secondarySort.GetValue(x, null))
.ProjectTo<TSeedDto>()
.ProjectTo<TSeedDto>(Mapper.ConfigurationProvider)
.ToArrayAsync();
}
}

View file

@ -1,4 +1,5 @@
using FilterLists.Data;
using AutoMapper;
using FilterLists.Data;
using JetBrains.Annotations;
namespace FilterLists.Services
@ -6,11 +7,18 @@ namespace FilterLists.Services
[UsedImplicitly]
public class Service
{
protected FilterListsDbContext DbContext;
protected readonly FilterListsDbContext DbContext;
protected readonly IMapper Mapper;
public Service(FilterListsDbContext dbContext)
{
DbContext = dbContext;
}
public Service(FilterListsDbContext dbContext, IMapper mapper)
{
DbContext = dbContext;
Mapper = mapper;
}
}
}

View file

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using FilterLists.Data;
using JetBrains.Annotations;
@ -15,9 +16,8 @@ public class SnapshotService : Service
//TODO: update algorithm to support non-standard list sizes and formats (#200, #201)
private readonly List<uint> ignoreLists = new List<uint> {48, 149, 173, 185, 186, 187, 188, 189, 352};
public SnapshotService(FilterListsDbContext dbContext) : base(dbContext)
public SnapshotService(FilterListsDbContext dbContext, IMapper mapper) : base(dbContext, mapper)
{
DbContext = dbContext;
}
public async Task CaptureAsync(int batchSize)
@ -46,7 +46,7 @@ await DbContext
.ThenBy(list =>
list.Snapshots.Select(ss => ss.CreatedDateUtc).OrderByDescending(sscd => sscd).FirstOrDefault())
.Take(batchSize)
.ProjectTo<FilterListViewUrlDto>()
.ProjectTo<FilterListViewUrlDto>(Mapper.ConfigurationProvider)
.ToListAsync();
private IEnumerable<SnapshotDe> GetSnapshots(IEnumerable<FilterListViewUrlDto> lists) =>