From 8dd524ca0ea096cadce9be45d57328ecdf19d0cd Mon Sep 17 00:00:00 2001 From: "hualin.zhu" Date: Thu, 7 Nov 2024 20:42:37 +0800 Subject: [PATCH] use mappery instead of automapper --- src/CleanArchitectureCodeGenerator.csproj | 3 + src/CodeGeneratorPackage.cs | 1 + src/Templatemap.cs | 1 + src/Templates/Commands/AddEdit/.cs.txt | 75 +++++++++-------------- src/Templates/Commands/Create/.cs.txt | 23 ++----- src/Templates/Commands/Delete/.cs.txt | 65 +++++++++----------- src/Templates/Commands/Import/.cs.txt | 9 +-- src/Templates/Commands/Update/.cs.txt | 60 +++++++----------- src/Templates/DTOs/.dto.cs.txt | 7 --- src/Templates/Mappers/.mapper.cs.txt | 26 ++++++++ src/Templates/Pages/.edit.razor.txt | 3 +- src/Templates/Pages/.razor.txt | 12 +--- src/Templates/Queries/Export/.cs.txt | 6 +- src/Templates/Queries/GetAll/.cs.txt | 17 ++--- src/Templates/Queries/GetById/.cs.txt | 14 ++--- src/Templates/Queries/Pagination/.cs.txt | 16 +++-- 16 files changed, 143 insertions(+), 195 deletions(-) create mode 100644 src/Templates/Mappers/.mapper.cs.txt diff --git a/src/CleanArchitectureCodeGenerator.csproj b/src/CleanArchitectureCodeGenerator.csproj index e186c1f..d1782f5 100644 --- a/src/CleanArchitectureCodeGenerator.csproj +++ b/src/CleanArchitectureCodeGenerator.csproj @@ -111,6 +111,9 @@ source.extension.vsixmanifest + + true + true diff --git a/src/CodeGeneratorPackage.cs b/src/CodeGeneratorPackage.cs index 517b547..820a584 100644 --- a/src/CodeGeneratorPackage.cs +++ b/src/CodeGeneratorPackage.cs @@ -125,6 +125,7 @@ private void ExecuteAsync(object sender, EventArgs e) $"{nameofPlural}/Commands/Import/Import{nameofPlural}CommandValidator.cs", $"{nameofPlural}/Caching/{name}CacheKey.cs", $"{nameofPlural}/DTOs/{name}Dto.cs", + $"{nameofPlural}/Mappers/{name}Mapper.cs", $"{nameofPlural}/EventHandlers/{name}CreatedEventHandler.cs", $"{nameofPlural}/EventHandlers/{name}UpdatedEventHandler.cs", $"{nameofPlural}/EventHandlers/{name}DeletedEventHandler.cs", diff --git a/src/Templatemap.cs b/src/Templatemap.cs index 55e0321..d7017fb 100644 --- a/src/Templatemap.cs +++ b/src/Templatemap.cs @@ -46,6 +46,7 @@ public static async Task GetTemplateFilePathAsync(Project project, Intel "Commands\\AddEdit", "Commands\\Import", "DTOs", + "Mappers", "Caching", "EventHandlers", "Events", diff --git a/src/Templates/Commands/AddEdit/.cs.txt b/src/Templates/Commands/AddEdit/.cs.txt index d1f5e3f..5fc7a8e 100644 --- a/src/Templates/Commands/AddEdit/.cs.txt +++ b/src/Templates/Commands/AddEdit/.cs.txt @@ -3,6 +3,8 @@ using {selectns}.{nameofPlural}.DTOs; using {selectns}.{nameofPlural}.Caching; +using {selectns}.{nameofPlural}.Mappers; + namespace {namespace}; public class AddEdit{itemname}Command: ICacheInvalidatorRequest> @@ -13,58 +15,41 @@ public class AddEdit{itemname}Command: ICacheInvalidatorRequest> public string CacheKey => {itemname}CacheKey.GetAllCacheKey; public CancellationTokenSource? SharedExpiryTokenSource => {itemname}CacheKey.GetOrCreateTokenSource(); +} - private class Mapping : Profile +public class AddEdit{itemname}CommandHandler : IRequestHandler> +{ + private readonly IApplicationDbContext _context; + public AddEdit{itemname}CommandHandler( + IApplicationDbContext context) { - public Mapping() - { - CreateMap<{itemname}Dto,AddEdit{itemname}Command>(MemberList.None); - CreateMap(MemberList.None); - - } + _context = context; } -} - - public class AddEdit{itemname}CommandHandler : IRequestHandler> + public async Task> Handle(AddEdit{itemname}Command request, CancellationToken cancellationToken) { - private readonly IApplicationDbContext _context; - private readonly IMapper _mapper; - private readonly IStringLocalizer _localizer; - public AddEdit{itemname}CommandHandler( - IApplicationDbContext context, - IStringLocalizer localizer, - IMapper mapper - ) + if (request.Id > 0) { - _context = context; - _localizer = localizer; - _mapper = mapper; - } - public async Task> Handle(AddEdit{itemname}Command request, CancellationToken cancellationToken) - { - if (request.Id > 0) - { - var item = await _context.{nameofPlural}.FindAsync(request.Id, cancellationToken); - if (item == null) - { - return await Result.FailureAsync($"{itemname} with id: [{request.Id}] not found."); - } - item = _mapper.Map(request, item); - // raise a update domain event - item.AddDomainEvent(new {itemname}UpdatedEvent(item)); - await _context.SaveChangesAsync(cancellationToken); - return await Result.SuccessAsync(item.Id); - } - else + var item = await _context.{nameofPlural}.FindAsync(request.Id, cancellationToken); + if (item == null) { - var item = _mapper.Map<{itemname}>(request); - // raise a create domain event - item.AddDomainEvent(new {itemname}CreatedEvent(item)); - _context.{nameofPlural}.Add(item); - await _context.SaveChangesAsync(cancellationToken); - return await Result.SuccessAsync(item.Id); + return await Result.FailureAsync($"{itemname} with id: [{request.Id}] not found."); } - + {itemname}Mapper.ApplyChangesFrom(request,item); + // raise a update domain event + item.AddDomainEvent(new {itemname}UpdatedEvent(item)); + await _context.SaveChangesAsync(cancellationToken); + return await Result.SuccessAsync(item.Id); } + else + { + var item = {itemname}Mapper.FromEditCommand(request); + // raise a create domain event + item.AddDomainEvent(new {itemname}CreatedEvent(item)); + _context.{nameofPlural}.Add(item); + await _context.SaveChangesAsync(cancellationToken); + return await Result.SuccessAsync(item.Id); + } + } +} diff --git a/src/Templates/Commands/Create/.cs.txt b/src/Templates/Commands/Create/.cs.txt index aaddf74..691540d 100644 --- a/src/Templates/Commands/Create/.cs.txt +++ b/src/Templates/Commands/Create/.cs.txt @@ -1,8 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.ComponentModel; -using {selectns}.{nameofPlural}.DTOs; + using {selectns}.{nameofPlural}.Caching; +using {selectns}.{nameofPlural}.Mappers; namespace {namespace}; @@ -13,34 +13,19 @@ public class Create{itemname}Command: ICacheInvalidatorRequest> {dtoFieldDefinition} public string CacheKey => {itemname}CacheKey.GetAllCacheKey; public CancellationTokenSource? SharedExpiryTokenSource => {itemname}CacheKey.GetOrCreateTokenSource(); - private class Mapping : Profile - { - public Mapping() - { - CreateMap<{itemname}Dto,Create{itemname}Command>(MemberList.None); - CreateMap(MemberList.None); - } - } } public class Create{itemname}CommandHandler : IRequestHandler> { private readonly IApplicationDbContext _context; - private readonly IMapper _mapper; - private readonly IStringLocalizer _localizer; public Create{itemname}CommandHandler( - IApplicationDbContext context, - IStringLocalizer localizer, - IMapper mapper - ) + IApplicationDbContext context) { _context = context; - _localizer = localizer; - _mapper = mapper; } public async Task> Handle(Create{itemname}Command request, CancellationToken cancellationToken) { - var item = _mapper.Map<{itemname}>(request); + var item = {itemname}Mapper.FromCreateCommand(request); // raise a create domain event item.AddDomainEvent(new {itemname}CreatedEvent(item)); _context.{nameofPlural}.Add(item); diff --git a/src/Templates/Commands/Delete/.cs.txt b/src/Templates/Commands/Delete/.cs.txt index ace30e9..2ff263a 100644 --- a/src/Templates/Commands/Delete/.cs.txt +++ b/src/Templates/Commands/Delete/.cs.txt @@ -6,46 +6,39 @@ using {selectns}.{nameofPlural}.Caching; namespace {namespace}; - public class Delete{itemname}Command: ICacheInvalidatorRequest> +public class Delete{itemname}Command: ICacheInvalidatorRequest> +{ + public int[] Id { get; } + public string CacheKey => {itemname}CacheKey.GetAllCacheKey; + public CancellationTokenSource? SharedExpiryTokenSource => {itemname}CacheKey.GetOrCreateTokenSource(); + public Delete{itemname}Command(int[] id) + { + Id = id; + } +} + +public class Delete{itemname}CommandHandler : + IRequestHandler> + +{ + private readonly IApplicationDbContext _context; + public Delete{itemname}CommandHandler( + IApplicationDbContext context) { - public int[] Id { get; } - public string CacheKey => {itemname}CacheKey.GetAllCacheKey; - public CancellationTokenSource? SharedExpiryTokenSource => {itemname}CacheKey.GetOrCreateTokenSource(); - public Delete{itemname}Command(int[] id) - { - Id = id; - } + _context = context; } - - public class Delete{itemname}CommandHandler : - IRequestHandler> - + public async Task> Handle(Delete{itemname}Command request, CancellationToken cancellationToken) { - private readonly IApplicationDbContext _context; - private readonly IMapper _mapper; - private readonly IStringLocalizer _localizer; - public Delete{itemname}CommandHandler( - IApplicationDbContext context, - IStringLocalizer localizer, - IMapper mapper - ) - { - _context = context; - _localizer = localizer; - _mapper = mapper; - } - public async Task> Handle(Delete{itemname}Command request, CancellationToken cancellationToken) + var items = await _context.{nameofPlural}.Where(x=>request.Id.Contains(x.Id)).ToListAsync(cancellationToken); + foreach (var item in items) { - var items = await _context.{nameofPlural}.Where(x=>request.Id.Contains(x.Id)).ToListAsync(cancellationToken); - foreach (var item in items) - { - // raise a delete domain event - item.AddDomainEvent(new {itemname}DeletedEvent(item)); - _context.{nameofPlural}.Remove(item); - } - var result = await _context.SaveChangesAsync(cancellationToken); - return await Result.SuccessAsync(result); + // raise a delete domain event + item.AddDomainEvent(new {itemname}DeletedEvent(item)); + _context.{nameofPlural}.Remove(item); } - + var result = await _context.SaveChangesAsync(cancellationToken); + return await Result.SuccessAsync(result); } +} + diff --git a/src/Templates/Commands/Import/.cs.txt b/src/Templates/Commands/Import/.cs.txt index 621cadf..d86c2e6 100644 --- a/src/Templates/Commands/Import/.cs.txt +++ b/src/Templates/Commands/Import/.cs.txt @@ -3,6 +3,7 @@ using {selectns}.{nameofPlural}.DTOs; using {selectns}.{nameofPlural}.Caching; +using {selectns}.{nameofPlural}.Mappers; namespace {namespace}; @@ -28,7 +29,6 @@ namespace {namespace}; IRequestHandler> { private readonly IApplicationDbContext _context; - private readonly IMapper _mapper; private readonly IStringLocalizer _localizer; private readonly IExcelService _excelService; private readonly {itemname}Dto _dto = new(); @@ -36,14 +36,11 @@ namespace {namespace}; public Import{nameofPlural}CommandHandler( IApplicationDbContext context, IExcelService excelService, - IStringLocalizer localizer, - IMapper mapper - ) + IStringLocalizer localizer) { _context = context; _localizer = localizer; _excelService = excelService; - _mapper = mapper; } #nullable disable warnings public async Task> Handle(Import{nameofPlural}Command request, CancellationToken cancellationToken) @@ -60,7 +57,7 @@ namespace {namespace}; var exists = await _context.{nameofPlural}.AnyAsync(x => x.Name == dto.Name, cancellationToken); if (!exists) { - var item = _mapper.Map<{itemname}>(dto); + var item = {itemname}Mapper.FromDto(dto); // add create domain events if this entity implement the IHasDomainEvent interface // item.AddDomainEvent(new {itemname}CreatedEvent(item)); await _context.{nameofPlural}.AddAsync(item, cancellationToken); diff --git a/src/Templates/Commands/Update/.cs.txt b/src/Templates/Commands/Update/.cs.txt index d3fe158..a2e53ef 100644 --- a/src/Templates/Commands/Update/.cs.txt +++ b/src/Templates/Commands/Update/.cs.txt @@ -1,8 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.ComponentModel; -using {selectns}.{nameofPlural}.DTOs; + using {selectns}.{nameofPlural}.Caching; +using {selectns}.{nameofPlural}.Mappers; namespace {namespace}; @@ -13,44 +13,30 @@ public class Update{itemname}Command: ICacheInvalidatorRequest> {dtoFieldDefinition} public string CacheKey => {itemname}CacheKey.GetAllCacheKey; public CancellationTokenSource? SharedExpiryTokenSource => {itemname}CacheKey.GetOrCreateTokenSource(); - private class Mapping : Profile - { - public Mapping() - { - CreateMap<{itemname}Dto,Update{itemname}Command>(MemberList.None); - CreateMap(MemberList.None); - } - } + } - public class Update{itemname}CommandHandler : IRequestHandler> +public class Update{itemname}CommandHandler : IRequestHandler> +{ + private readonly IApplicationDbContext _context; + public Update{itemname}CommandHandler( + IApplicationDbContext context) + { + _context = context; + } + public async Task> Handle(Update{itemname}Command request, CancellationToken cancellationToken) { - private readonly IApplicationDbContext _context; - private readonly IMapper _mapper; - private readonly IStringLocalizer _localizer; - public Update{itemname}CommandHandler( - IApplicationDbContext context, - IStringLocalizer localizer, - IMapper mapper - ) - { - _context = context; - _localizer = localizer; - _mapper = mapper; - } - public async Task> Handle(Update{itemname}Command request, CancellationToken cancellationToken) - { - var item = await _context.{nameofPlural}.FindAsync(request.Id, cancellationToken); - if (item == null) - { - return await Result.FailureAsync($"{itemname} with id: [{request.Id}] not found."); - } - item = _mapper.Map(request, item); - // raise a update domain event - item.AddDomainEvent(new {itemname}UpdatedEvent(item)); - await _context.SaveChangesAsync(cancellationToken); - return await Result.SuccessAsync(item.Id); - } + var item = await _context.{nameofPlural}.FindAsync(request.Id, cancellationToken); + if (item == null) + { + return await Result.FailureAsync($"{itemname} with id: [{request.Id}] not found."); + } + {itemname}Mapper.ApplyChangesFrom(request, item); + // raise a update domain event + item.AddDomainEvent(new {itemname}UpdatedEvent(item)); + await _context.SaveChangesAsync(cancellationToken); + return await Result.SuccessAsync(item.Id); } +} diff --git a/src/Templates/DTOs/.dto.cs.txt b/src/Templates/DTOs/.dto.cs.txt index 87fc26a..a8f55c5 100644 --- a/src/Templates/DTOs/.dto.cs.txt +++ b/src/Templates/DTOs/.dto.cs.txt @@ -10,12 +10,5 @@ public class {itemname}Dto public int Id { get; set; } {dtoFieldDefinition} - private class Mapping : Profile - { - public Mapping() - { - CreateMap<{itemname}, {itemname}Dto>().ReverseMap(); - } - } } diff --git a/src/Templates/Mappers/.mapper.cs.txt b/src/Templates/Mappers/.mapper.cs.txt new file mode 100644 index 0000000..ab9e08b --- /dev/null +++ b/src/Templates/Mappers/.mapper.cs.txt @@ -0,0 +1,26 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using {selectns}.{nameofPlural}.Commands.AddEdit; +using {selectns}.{nameofPlural}.Commands.Create; +using {selectns}.{nameofPlural}.Commands.Update; +using {selectns}.{nameofPlural}.DTOs; + +namespace {namespace}; + +#pragma warning disable RMG020 +#pragma warning disable RMG012 +[Mapper] +public static partial class {itemname}Mapper +{ + public static partial {itemname}Dto ToDto({itemname} source); + public static partial {itemname} FromDto({itemname}Dto dto); + public static partial {itemname} FromEditCommand(AddEdit{itemname}Command command); + public static partial {itemname} FromCreateCommand(Create{itemname}Command command); + public static partial Update{itemname}Command ToUpdateCommand({itemname}Dto dto); + public static partial AddEdit{itemname}Command CloneFromDto({itemname}Dto dto); + public static partial void ApplyChangesFrom(Update{itemname}Command source, {itemname} target); + public static partial void ApplyChangesFrom(AddEdit{itemname}Command source, {itemname} target); + public static partial IQueryable<{itemname}Dto> ProjectTo(this IQueryable<{itemname}> q); +} + diff --git a/src/Templates/Pages/.edit.razor.txt b/src/Templates/Pages/.edit.razor.txt index d513853..490c829 100644 --- a/src/Templates/Pages/.edit.razor.txt +++ b/src/Templates/Pages/.edit.razor.txt @@ -1,5 +1,6 @@ @page "/pages/{nameofPlural}/edit/{id:int}" @using CleanArchitecture.Blazor.Application.Features.{nameofPlural}.Commands.Update +@using CleanArchitecture.Blazor.Application.Features.{nameofPlural}.Mappers @using CleanArchitecture.Blazor.Application.Features.{nameofPlural}.Queries.GetById @inherits MudComponentBase @inject IValidationService Validator @@ -49,7 +50,7 @@ var result = await Mediator.Send(new Get{itemname}ByIdQuery() { Id = Id }); result.Map(data => { - model = Mapper.Map(data); + model = {itemname}Mapper.ToUpdateCommand(data); return data; }).Match(data => { diff --git a/src/Templates/Pages/.razor.txt b/src/Templates/Pages/.razor.txt index 926f8a5..f9d923f 100644 --- a/src/Templates/Pages/.razor.txt +++ b/src/Templates/Pages/.razor.txt @@ -3,6 +3,7 @@ @using BlazorDownloadFile @using CleanArchitecture.Blazor.Application.Features.{nameofPlural}.Caching @using CleanArchitecture.Blazor.Application.Features.{nameofPlural}.DTOs +@using CleanArchitecture.Blazor.Application.Features.{nameofPlural}.Mappers @using CleanArchitecture.Blazor.Application.Features.{nameofPlural}.Specifications @using CleanArchitecture.Blazor.Application.Features.{nameofPlural}.Commands.Delete @using CleanArchitecture.Blazor.Application.Features.{nameofPlural}.Commands.Import @@ -254,19 +255,12 @@ private async Task OnClone() { var dto = _selectedItems.First(); - var command = Mapper.Map<{itemname}Dto, AddEdit{itemname}Command>(dto, opts => - { - opts.AfterMap((src, dest) => - { - dest.Id = 0; - }); - }); + var command = {itemname}Mapper.CloneFromDto(dto); await ShowEditFormDialog(string.Format(ConstantString.CreateAnItem, L["{itemname}"]), command); } private async Task OnEdit({itemname}Dto dto) { - var command = Mapper.Map(dto); - await ShowEditFormDialog(string.Format(ConstantString.EditTheItem, L["{itemname}"]), command); + Navigation.NavigateTo($"/pages/{nameofPlural}/edit/{dto.Id}"); } private async Task OnDelete({itemname}Dto dto) diff --git a/src/Templates/Queries/Export/.cs.txt b/src/Templates/Queries/Export/.cs.txt index 23e9b05..b92632f 100644 --- a/src/Templates/Queries/Export/.cs.txt +++ b/src/Templates/Queries/Export/.cs.txt @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using {selectns}.{nameofPlural}.DTOs; +using {selectns}.{nameofPlural}.Mappers; using {selectns}.{nameofPlural}.Specifications; using {selectns}.{nameofPlural}.Queries.Pagination; @@ -16,19 +17,16 @@ public class Export{nameofPlural}QueryHandler : IRequestHandler> { private readonly IApplicationDbContext _context; - private readonly IMapper _mapper; private readonly IExcelService _excelService; private readonly IStringLocalizer _localizer; private readonly {itemname}Dto _dto = new(); public Export{nameofPlural}QueryHandler( IApplicationDbContext context, - IMapper mapper, IExcelService excelService, IStringLocalizer localizer ) { _context = context; - _mapper = mapper; _excelService = excelService; _localizer = localizer; } @@ -37,7 +35,7 @@ public class Export{nameofPlural}QueryHandler : { var data = await _context.{nameofPlural}.ApplySpecification(request.Specification) .OrderBy($"{request.OrderBy} {request.SortDirection}") - .ProjectTo<{itemname}Dto>(_mapper.ConfigurationProvider) + .ProjectTo() .AsNoTracking() .ToListAsync(cancellationToken); var result = await _excelService.ExportAsync(data, diff --git a/src/Templates/Queries/GetAll/.cs.txt b/src/Templates/Queries/GetAll/.cs.txt index 82e2f3e..2e32788 100644 --- a/src/Templates/Queries/GetAll/.cs.txt +++ b/src/Templates/Queries/GetAll/.cs.txt @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using {selectns}.{nameofPlural}.DTOs; +using {selectns}.{nameofPlural}.Mappers; using {selectns}.{nameofPlural}.Caching; namespace {namespace}; @@ -16,26 +17,18 @@ public class GetAll{nameofPlural}QueryHandler : IRequestHandler> { private readonly IApplicationDbContext _context; - private readonly IMapper _mapper; - private readonly IStringLocalizer _localizer; public GetAll{nameofPlural}QueryHandler( - IApplicationDbContext context, - IMapper mapper, - IStringLocalizer localizer - ) + IApplicationDbContext context) { _context = context; - _mapper = mapper; - _localizer = localizer; } public async Task> Handle(GetAll{nameofPlural}Query request, CancellationToken cancellationToken) { - var data = await _context.{nameofPlural} - .ProjectTo<{itemname}Dto>(_mapper.ConfigurationProvider) - .AsNoTracking() - .ToListAsync(cancellationToken); + var data = await _context.{nameofPlural}.ProjectTo() + .AsNoTracking() + .ToListAsync(cancellationToken); return data; } } diff --git a/src/Templates/Queries/GetById/.cs.txt b/src/Templates/Queries/GetById/.cs.txt index 8f98e66..c93b04a 100644 --- a/src/Templates/Queries/GetById/.cs.txt +++ b/src/Templates/Queries/GetById/.cs.txt @@ -3,6 +3,7 @@ using {selectns}.{nameofPlural}.DTOs; using {selectns}.{nameofPlural}.Caching; +using {selectns}.{nameofPlural}.Mappers; using {selectns}.{nameofPlural}.Specifications; namespace {namespace}; @@ -18,25 +19,18 @@ public class Get{itemname}ByIdQueryHandler : IRequestHandler> { private readonly IApplicationDbContext _context; - private readonly IMapper _mapper; - private readonly IStringLocalizer _localizer; public Get{itemname}ByIdQueryHandler( - IApplicationDbContext context, - IMapper mapper, - IStringLocalizer localizer - ) + IApplicationDbContext context) { _context = context; - _mapper = mapper; - _localizer = localizer; } public async Task> Handle(Get{itemname}ByIdQuery request, CancellationToken cancellationToken) { var data = await _context.{nameofPlural}.ApplySpecification(new {itemname}ByIdSpecification(request.Id)) - .ProjectTo<{itemname}Dto>(_mapper.ConfigurationProvider) - .FirstAsync(cancellationToken); + .ProjectTo() + .FirstAsync(cancellationToken); return await Result.SuccessAsync(data); } } diff --git a/src/Templates/Queries/Pagination/.cs.txt b/src/Templates/Queries/Pagination/.cs.txt index b475c10..2d33038 100644 --- a/src/Templates/Queries/Pagination/.cs.txt +++ b/src/Templates/Queries/Pagination/.cs.txt @@ -3,6 +3,7 @@ using {selectns}.{nameofPlural}.DTOs; using {selectns}.{nameofPlural}.Caching; +using {selectns}.{nameofPlural}.Mappers; using {selectns}.{nameofPlural}.Specifications; namespace {namespace}; @@ -22,24 +23,21 @@ public class {nameofPlural}WithPaginationQueryHandler : IRequestHandler<{nameofPlural}WithPaginationQuery, PaginatedData<{itemname}Dto>> { private readonly IApplicationDbContext _context; - private readonly IMapper _mapper; - private readonly IStringLocalizer<{nameofPlural}WithPaginationQueryHandler> _localizer; public {nameofPlural}WithPaginationQueryHandler( - IApplicationDbContext context, - IMapper mapper, - IStringLocalizer<{nameofPlural}WithPaginationQueryHandler> localizer - ) + IApplicationDbContext context) { _context = context; - _mapper = mapper; - _localizer = localizer; } public async Task> Handle({nameofPlural}WithPaginationQuery request, CancellationToken cancellationToken) { var data = await _context.{nameofPlural}.OrderBy($"{request.OrderBy} {request.SortDirection}") - .ProjectToPaginatedDataAsync<{itemname}, {itemname}Dto>(request.Specification, request.PageNumber, request.PageSize, _mapper.ConfigurationProvider, cancellationToken); + .ProjectToPaginatedDataAsync(request.Specification, + request.PageNumber, + request.PageSize, + {itemname}Mapper.ToDto, + cancellationToken); return data; } } \ No newline at end of file