Skip to content

Conversation

@neozhu
Copy link
Owner

@neozhu neozhu commented Jun 25, 2023

refer to jasontaylordev/CleanArchitecture#871

Overview

Simplified the object-object mapping approach by removing IMapFrom and associated MappingProfile. Mappings can now be specified using a standard AutoMapper.Profile as nested classes or in separate files as appropriate.

Motivation

The previous approach was becoming cumbersome to maintain and didn't align well with our project requirements. Removing IMapFrom and the associated MappingProfile will streamline the mapping process and improve code clarity.

Changes Made

Removed IMapFrom and associated MappingProfile.
Introduced the use of AutoMapper.Profile as nested classes or in separate files for specifying mappings.
Updated the usage of AutoMapper to closely follow the AutoMapper Usage Guidelines.
Example
Here's an example of the new mapping approach:

public class TodoItemDto
{
    public int Id { get; init; }

    public string? Title { get; init; }

    public bool Done { get; init; }

    public int Priority { get; init; }

    private class Mapping : Profile
    {
        public Mapping()
        {
            CreateMap<TodoItem, TodoItemDto>().ForMember(d => d.Priority, 
                opt => opt.MapFrom(s => (int)s.Priority));
        }
    }
}

@neozhu neozhu requested a review from Bram1903 June 25, 2023 12:46
@neozhu neozhu added the Enhancement New feature or request label Jun 25, 2023
Copy link
Collaborator

@Bram1903 Bram1903 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! It indeed increases code clarity, and looks way more structured!

@Bram1903 Bram1903 merged commit 34f094e into main Jun 25, 2023
@Bram1903 Bram1903 deleted the SimplifyMapping branch June 25, 2023 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants