From 54f773f18fc74d9227768db50747084b7523971d Mon Sep 17 00:00:00 2001 From: Enis Necipoglu Date: Thu, 28 Aug 2025 08:13:07 +0300 Subject: [PATCH] Migrate from AutoMapper to Mapperly in tenant management Replaced AutoMapper usage with Mapperly in tenant management and MVC template modules. Removed obsolete AutoMapper mapping profile, updated project references and module dependencies, and refactored mapping configuration methods to use Mapperly. --- ...bpTenantManagementDomainMapperlyMappers.cs | 22 +----------- ...AbpTenantManagementDomainMappingProfile.cs | 36 ------------------- .../AbpTenantManagementWebMapperlyMappers.cs | 7 +++- .../MyCompanyName.MyProjectName.Mvc.csproj | 2 +- .../MyProjectNameModule.cs | 19 ++++------ 5 files changed, 14 insertions(+), 72 deletions(-) delete mode 100644 modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/AbpTenantManagementDomainMappingProfile.cs diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/AbpTenantManagementDomainMapperlyMappers.cs b/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/AbpTenantManagementDomainMapperlyMappers.cs index 81b9faf1d8..d2904c844b 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/AbpTenantManagementDomainMapperlyMappers.cs +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/AbpTenantManagementDomainMapperlyMappers.cs @@ -7,34 +7,14 @@ using Volo.Abp.MultiTenancy; namespace Volo.Abp.TenantManagement.Domain.Volo.Abp.TenantManagement; -[Mapper] +[Mapper(RequiredMappingStrategy = RequiredMappingStrategy.Target)] public partial class TenantToTenantConfigurationMapper : MapperBase { - [MapperIgnoreSource(nameof(Tenant.DeleterId))] - [MapperIgnoreSource(nameof(Tenant.DeletionTime))] - [MapperIgnoreSource(nameof(Tenant.LastModificationTime))] - [MapperIgnoreSource(nameof(Tenant.CreationTime))] - [MapperIgnoreSource(nameof(Tenant.CreatorId))] - [MapperIgnoreSource(nameof(Tenant.LastModifierId))] - [MapperIgnoreSource(nameof(Tenant.ExtraProperties))] - [MapperIgnoreSource(nameof(Tenant.ConcurrencyStamp))] - [MapperIgnoreSource(nameof(Tenant.IsDeleted))] - [MapperIgnoreSource(nameof(Tenant.EntityVersion))] [MapperIgnoreTarget(nameof(TenantConfiguration.EditionId))] [MapperIgnoreTarget(nameof(TenantConfiguration.IsActive))] public override partial TenantConfiguration Map(Tenant source); - [MapperIgnoreSource(nameof(Tenant.DeleterId))] - [MapperIgnoreSource(nameof(Tenant.DeletionTime))] - [MapperIgnoreSource(nameof(Tenant.IsDeleted))] - [MapperIgnoreSource(nameof(Tenant.LastModificationTime))] - [MapperIgnoreSource(nameof(Tenant.LastModifierId))] - [MapperIgnoreSource(nameof(Tenant.CreationTime))] - [MapperIgnoreSource(nameof(Tenant.CreatorId))] - [MapperIgnoreSource(nameof(Tenant.ExtraProperties))] - [MapperIgnoreSource(nameof(Tenant.ConcurrencyStamp))] - [MapperIgnoreSource(nameof(Tenant.EntityVersion))] [MapperIgnoreTarget(nameof(TenantConfiguration.EditionId))] [MapperIgnoreTarget(nameof(TenantConfiguration.IsActive))] public override partial void Map(Tenant source, TenantConfiguration destination); diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/AbpTenantManagementDomainMappingProfile.cs b/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/AbpTenantManagementDomainMappingProfile.cs deleted file mode 100644 index 0b0795d681..0000000000 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/AbpTenantManagementDomainMappingProfile.cs +++ /dev/null @@ -1,36 +0,0 @@ -// using AutoMapper; -using Volo.Abp.Data; -using Volo.Abp.MultiTenancy; - -namespace Volo.Abp.TenantManagement; - -public class AbpTenantManagementDomainMappingProfile //: Profile -{ - public AbpTenantManagementDomainMappingProfile() - { - // CreateMap() - // .ForMember(ti => ti.ConnectionStrings, opts => - // { - // opts.MapFrom((tenant, ti) => - // { - // var connStrings = new ConnectionStrings(); - - // if (tenant.ConnectionStrings == null) - // { - // return connStrings; - // } - - // foreach (var connectionString in tenant.ConnectionStrings) - // { - // connStrings[connectionString.Name] = connectionString.Value; - // } - - // return connStrings; - // }); - // }) - // .ForMember(x => x.IsActive, x => x.Ignore()) - // .ForMember(x => x.EditionId, x => x.Ignore()); - - // CreateMap(); - } -} diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/AbpTenantManagementWebMapperlyMappers.cs b/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/AbpTenantManagementWebMapperlyMappers.cs index b27aefe808..7b6f3d389d 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/AbpTenantManagementWebMapperlyMappers.cs +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/AbpTenantManagementWebMapperlyMappers.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Riok.Mapperly.Abstractions; +using Volo.Abp.DependencyInjection; using Volo.Abp.Mapperly; using Volo.Abp.TenantManagement.Web.Pages.TenantManagement.Tenants; @@ -19,7 +20,7 @@ public partial class TenantDtoToTenantInfoModelMapper [Mapper] public partial class TenantInfoModelToTenantCreateDtoMapper - : MapperBase + : TwoWayMapperBase { [MapperIgnoreSource(nameof(EditModalModel.TenantInfoModel.Id))] [MapperIgnoreSource(nameof(EditModalModel.TenantInfoModel.ConcurrencyStamp))] @@ -32,6 +33,10 @@ public partial class TenantInfoModelToTenantCreateDtoMapper [MapperIgnoreTarget(nameof(TenantCreateDto.AdminEmailAddress))] [MapperIgnoreTarget(nameof(TenantCreateDto.AdminPassword))] public override partial void Map(EditModalModel.TenantInfoModel source, TenantCreateDto destination); + + public override partial EditModalModel.TenantInfoModel ReverseMap(TenantCreateDto source); + + public override partial void ReverseMap(TenantCreateDto source, EditModalModel.TenantInfoModel destination); } [Mapper] diff --git a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/MyCompanyName.MyProjectName.Mvc.csproj b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/MyCompanyName.MyProjectName.Mvc.csproj index 3d70cebc18..148f1afd74 100644 --- a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/MyCompanyName.MyProjectName.Mvc.csproj +++ b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/MyCompanyName.MyProjectName.Mvc.csproj @@ -23,7 +23,7 @@ - + diff --git a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/MyProjectNameModule.cs b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/MyProjectNameModule.cs index e8c99fc852..39aa8b36c1 100644 --- a/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/MyProjectNameModule.cs +++ b/templates/app-nolayers/aspnet-core/MyCompanyName.MyProjectName.Mvc/MyProjectNameModule.cs @@ -18,7 +18,7 @@ using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; using Volo.Abp.AspNetCore.Serilog; using Volo.Abp.AuditLogging.EntityFrameworkCore; using Volo.Abp.Autofac; -using Volo.Abp.AutoMapper; +using Volo.Abp.Mapperly; using Volo.Abp.Emailing; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.SqlServer; @@ -57,7 +57,7 @@ namespace MyCompanyName.MyProjectName; // ABP Framework packages typeof(AbpAspNetCoreMvcModule), typeof(AbpAutofacModule), - typeof(AbpAutoMapperModule), + typeof(AbpMapperlyModule), typeof(AbpEntityFrameworkCoreSqlServerModule), typeof(AbpSwashbuckleModule), typeof(AbpAspNetCoreSerilogModule), @@ -162,7 +162,7 @@ public class MyProjectNameModule : AbpModule ConfigureMultiTenancy(); ConfigureUrls(configuration); ConfigureBundles(); - ConfigureAutoMapper(context); + ConfigureMapperly(context); ConfigureSwagger(context.Services); ConfigureNavigationServices(); ConfigureAutoApiControllers(); @@ -291,17 +291,10 @@ public class MyProjectNameModule : AbpModule ); } - private void ConfigureAutoMapper(ServiceConfigurationContext context) + private void ConfigureMapperly(ServiceConfigurationContext context) { - context.Services.AddAutoMapperObjectMapper(); - Configure(options => - { - /* Uncomment `validate: true` if you want to enable the Configuration Validation feature. - * See AutoMapper's documentation to learn what it is: - * https://docs.automapper.org/en/stable/Configuration-validation.html - */ - options.AddMaps(/* validate: true */); - }); + context.Services.AddMapperlyObjectMapper(); + context.Services.AddMapperlyObjectMapper(); } private void ConfigureEfCore(ServiceConfigurationContext context)