From f415e73807eff2106313544dd9d22d870b82400c Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 7 Aug 2025 19:38:32 +0800 Subject: [PATCH] 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(); }