From 34d6f64bb3607e88795123ef80d8562fd2536f5c Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 7 Aug 2025 17:48:36 +0800 Subject: [PATCH 1/3] Disable `MapperlyAutoObjectMappingProvider` if AutoMapper used in app. This is the temporary solution, We will remove it in when all apps are migrated to Mapperly. --- .../Volo/Abp/Mapperly/AbpMapperlyModule.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/AbpMapperlyModule.cs b/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/AbpMapperlyModule.cs index 60381163eb..87cf270cee 100644 --- a/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/AbpMapperlyModule.cs +++ b/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/AbpMapperlyModule.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.DependencyInjection; +using System.Linq; +using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Auditing; using Volo.Abp.Modularity; using Volo.Abp.ObjectExtending; @@ -20,6 +21,11 @@ public class AbpMapperlyModule : AbpModule public override void ConfigureServices(ServiceConfigurationContext context) { - context.Services.AddMapperlyObjectMapper(); + // This is the temporary solution, We will remove it in when all apps are migrated to Mapperly. + var autoMapperModule = context.Services.FirstOrDefault(x => x.ServiceType.FullName == "Volo.Abp.AutoMapper.AbpAutoMapperModule"); + if (autoMapperModule == null) + { + context.Services.AddMapperlyObjectMapper(); + } } } From c417972c29eb5681cd2d2faf0b84a9b0a6601737 Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 7 Aug 2025 18:05:28 +0800 Subject: [PATCH 2/3] Update module registration order check in AbpMapperlyModule --- .../Volo/Abp/Mapperly/AbpMapperlyModule.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/AbpMapperlyModule.cs b/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/AbpMapperlyModule.cs index 87cf270cee..15ee42d930 100644 --- a/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/AbpMapperlyModule.cs +++ b/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/AbpMapperlyModule.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Auditing; using Volo.Abp.Modularity; @@ -22,8 +23,11 @@ public class AbpMapperlyModule : AbpModule public override void ConfigureServices(ServiceConfigurationContext context) { // This is the temporary solution, We will remove it in when all apps are migrated to Mapperly. - var autoMapperModule = context.Services.FirstOrDefault(x => x.ServiceType.FullName == "Volo.Abp.AutoMapper.AbpAutoMapperModule"); - if (autoMapperModule == null) + var abpApplication = context.Services.GetSingletonInstance(); + var modules = abpApplication.Modules.ToList(); + var autoMapperModuleIndex = modules.FindIndex(x => x.Type.FullName!.Equals("Volo.Abp.AutoMapper.AbpAutoMapperModule", StringComparison.OrdinalIgnoreCase)); + var mapperlyModuleIndex = modules.FindIndex(x => x.Type == typeof(AbpMapperlyModule)); + if (mapperlyModuleIndex < autoMapperModuleIndex) { context.Services.AddMapperlyObjectMapper(); } From f415e73807eff2106313544dd9d22d870b82400c Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 7 Aug 2025 19:38:32 +0800 Subject: [PATCH 3/3] Update Mapperly module registration logic --- .../Volo/Abp/Mapperly/AbpMapperlyModule.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/AbpMapperlyModule.cs b/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/AbpMapperlyModule.cs index 15ee42d930..f879354ed3 100644 --- a/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/AbpMapperlyModule.cs +++ b/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/AbpMapperlyModule.cs @@ -23,11 +23,20 @@ public class AbpMapperlyModule : AbpModule public override void ConfigureServices(ServiceConfigurationContext context) { // This is the temporary solution, We will remove it in when all apps are migrated to Mapperly. - var abpApplication = context.Services.GetSingletonInstance(); - var modules = abpApplication.Modules.ToList(); + var disableMapperlyAutoObjectMappingProvider = false; + + var modules = context.Services.GetSingletonInstance().Modules.ToList(); var autoMapperModuleIndex = modules.FindIndex(x => x.Type.FullName!.Equals("Volo.Abp.AutoMapper.AbpAutoMapperModule", StringComparison.OrdinalIgnoreCase)); - var mapperlyModuleIndex = modules.FindIndex(x => x.Type == typeof(AbpMapperlyModule)); - if (mapperlyModuleIndex < autoMapperModuleIndex) + if (autoMapperModuleIndex >= 0) + { + var mapperlyModuleIndex = modules.FindIndex(x => x.Type == typeof(AbpMapperlyModule)); + if (mapperlyModuleIndex > autoMapperModuleIndex) + { + disableMapperlyAutoObjectMappingProvider = true; + } + } + + if (!disableMapperlyAutoObjectMappingProvider) { context.Services.AddMapperlyObjectMapper(); }