Skip to content

Allow multiple IncludeMappingConfiguration attributes on the same method #2315

Description

@geferon

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).

// 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions