Repository: riok/mapperly (2026-06-22T14:24:54Z)

Issue:
Allow multiple `IncludeMappingConfiguration` attributes on the same method
**Is your feature request related to a problem? Please describe.**
In my app, I have multiple interfaces that contain different properties, and there are classes that use multiple at the same time, and I would like to provide mappers for each interface type so that re-using the configuration for these is easy to do.

**Describe the solution you'd like**
Either make `UseMapper` / `UseStaticMapper` infer if there is any derived/inherited mappers that can be re-used automatically, or allow the usage of multiple `IncludeMappingConfiguration` attributes (since the framework currently only allows one).

```csharp
// Original interfaces
public interface IAudit {
  public string CreatedBy { get; set; }
  public DateTime CreationDate { get; set; }
}

public interface IOwnable {
  public string? Owner { get; set; }
}

public class House : IAudit, IOwnable { ... }

public class Form : IAudit, IOwnable { ... }

// DTOs / Mappers
// Assume that there are respective DTOs interfaces and classes
// IAuditDto, IOwnableDto, HouseDto (IAuditDto, IOwnableDto), FormDto (IAuditDto, IOwnableDto)

[Mapper]
public static partial class BaseMapper {
  public static partial void MapAudit(IAudit audit, IAuditDto auditDto);
  public static partial void MapOwnable(IOwnable ownable, IOwnableDto ownableDto);
}

[Mapper]
[UseStaticMaper(typeof(BaseMapper))] // Either have this automatically infer the usage of BaseMapper.MapAudit/MapOwnable
public static partial class HouseMapper {
  // Or allow this?
  [IncludeMappingConfiguration(nameof(@BaseMapper .MapAudit))]
  [IncludeMappingConfiguration(nameof(@BaseMapper .MapOwnable))]
  public static partial HouseDto ToDto(this House house);
}

// Same for Form
```

**Describe alternatives you've considered**
So far the only solution is re-specifying the mapping config for these two in each mapper that uses them.



Discussion:
Thanks for the write-up. Two separate asks here:
 
Multiple `IncludeMappingConfiguration`: I think most of the Mapperly code can already handle this, shouldn't be too hard to enable this.

Auto-inferring includes from `UseStaticMapper`: we'd rather not. It's implicit and ambiguous (which mapper wins if two map the same), and goes against Mapperly's explicit-by-design approach. The multiple-attribute path above solves the same thing explicitly.



Patch:
diff --git a/src/Riok.Mapperly.Abstractions/IncludeMappingConfigurationAttribute.cs b/src/Riok.Mapperly.Abstractions/IncludeMappingConfigurationAttribute.cs
index 7456ba65d2..44b5e090de 100644
--- a/src/Riok.Mapperly.Abstractions/IncludeMappingConfigurationAttribute.cs
+++ b/src/Riok.Mapperly.Abstractions/IncludeMappingConfigurationAttribute.cs
@@ -6,7 +6,7 @@ namespace Riok.Mapperly.Abstractions;
 /// An attribute used to include the mapping configuration of another mapping method in the attributed method.
 /// Use the other mapping's method name to identify the configuration.
 /// </summary>
-[AttributeUsage(AttributeTargets.Method)]
+[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
 [Conditional("MAPPERLY_ABSTRACTIONS_SCOPE_RUNTIME")]
 public sealed class IncludeMappingConfigurationAttribute : Attribute
 {


Test patch:
diff --git a/test/Riok.Mapperly.Abstractions.Tests/_snapshots/PublicApiTest.PublicApiHasNotChanged.verified.cs b/test/Riok.Mapperly.Abstractions.Tests/_snapshots/PublicApiTest.PublicApiHasNotChanged.verified.cs
index 3ad1c41b2f..2491f7d24b 100644
--- a/test/Riok.Mapperly.Abstractions.Tests/_snapshots/PublicApiTest.PublicApiHasNotChanged.verified.cs
+++ b/test/Riok.Mapperly.Abstractions.Tests/_snapshots/PublicApiTest.PublicApiHasNotChanged.verified.cs
@@ -34,7 +34,7 @@ public enum IgnoreObsoleteMembersStrategy
         Source = 1,
         Target = 2,
     }
-    [System.AttributeUsage(System.AttributeTargets.Method)]
+    [System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=true)]
     [System.Diagnostics.Conditional("MAPPERLY_ABSTRACTIONS_SCOPE_RUNTIME")]
     public sealed class IncludeMappingConfigurationAttribute : System.Attribute
     {