F
F
FairyFox57002020-04-16 16:26:05
ASP.NET
FairyFox5700, 2020-04-16 16:26:05

How to implement custom object mapping in ASP NET CORE MVC?

Such a question
I was told that the Automapper is evil and it is better not to use it.
How then to deal with my implementation of the mapper without displaying c#
I mean, it’s tedious for me to use and create my own mapper class for each DTO for each VIewModel?
For example there

public class RoleMapperUpdateModel : IMapper<RoleDTO, UpdateRoleViewModel>
    {
        public UpdateRoleViewModel Map(RoleDTO source)
        {
            return new UpdateRoleViewModel()
            {
                Id = source.Id,
                Name = source.Name,
                Users = source.Users
            };
        }

        public RoleDTO MapBack(UpdateRoleViewModel destination)
        {
            return new RoleDTO()
            {
                Id = destination.Id,
                Name = destination.Name,
                Users = destination.Users
            };
        }
    }

and so for all
If yes, then how to be?
Is it better to move the mapper to a separate project and use it already in the logic layer and the presentation layer
Or is it better to create just a daddy with all the mapper classes on different layers?
Thanks in advance?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2020-04-16
@FairyFox5700

Might be worth asking

I was told that the Automapper is evil and should not be used.

And remind him of the principle of do not reinvent the next wheel?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question