From e020f09b9e5fa4ee1c4745759e23e4db36a984a6 Mon Sep 17 00:00:00 2001 From: maliming Date: Fri, 8 Aug 2025 09:44:00 +0800 Subject: [PATCH] Add guidance for setting default mapping provider --- .../AutoMapper-To-Mapperly.md | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/en/release-info/migration-guides/AutoMapper-To-Mapperly.md b/docs/en/release-info/migration-guides/AutoMapper-To-Mapperly.md index 2b0c5b623d..11112e2bc6 100644 --- a/docs/en/release-info/migration-guides/AutoMapper-To-Mapperly.md +++ b/docs/en/release-info/migration-guides/AutoMapper-To-Mapperly.md @@ -182,3 +182,30 @@ Please refer to the [Mapperly documentation](https://mapperly.riok.app/docs/intr - [Mapperly Configuration](https://mapperly.riok.app/docs/configuration/mapper/) - [Mapperly Enums](https://mapperly.riok.app/docs/configuration/enum/) - [Mapperly Flattening and unflattening](https://mapperly.riok.app/docs/configuration/flattening/) + + +## Set Default Mapping Provider + +When your project contains modules using both AutoMapper and Mapperly, you may need to explicitly set the default `IAutoObjectMappingProvider` to ensure consistent behavior across your application. + +If your application uses `AutoMapper`: + +```csharp +public override void ConfigureServices(ServiceConfigurationContext context) +{ + context.Services.AddAutoMapperObjectMapper(); +} +``` + +If your application uses `Mapperly`: + +```csharp +public override void ConfigureServices(ServiceConfigurationContext context) +{ + context.Services.AddMapperlyObjectMapper(); +} +``` + +### Why Set Default Mapping Provider? + +When your project contains modules using both AutoMapper and Mapperly, both `AbpAutoMapperModule` and `AbpMapperlyModule` will be loaded. Their dependency order may vary based on your project's module structure, and the last loaded module will override the `IAutoObjectMappingProvider` implementation. This could lead to unexpected behavior. Setting an explicit default ensures predictable mapping behavior throughout your application.