How to Deploy AutoMapper 6.2.2

2

I'm following a tutorial in which classes are configured as follows:

A class named AutoMapperConfig:

public class AutoMapperConfig
{

    public static void RegisterMappings()
    {

        Mapper.Initialize(x =>
        {
            x.AddProfile<DomainToViewModelMappingProfile>();
            x.AddProfile<ViewModelToDomainMappingProfile>();
        });

    }
}

Another class called DomainToViewModelMappingProfile, which does the mapping from Domain to ViewModel:

public class DomainToViewModelMappingProfile : Profile
{

    public override string ProfileName
    {
        get { return "ViewModelToDomainMappings"; }
    }

    protected override void Configure()
    {
        CreateMap<ClienteViewModel, Cliente>();
        CreateMap<ProdutoViewModel, Produto>();
    }

}

And a third called ViewModelToDomainMappingProfile that maps from ViewModel to the Domain:

public class ViewModelToDomainMappingProfile : Profile
{

    public override string ProfileName
    {
        get { return "DomainToViewModelMappings"; }
    }

    protected override void Configure()
    {
        CreateMap<ClienteViewModel, Cliente>();
        CreateMap<ProdutoViewModel, Produto>();
    }
}

What happens is that in:

protected override void Configure()

asked by anonymous 20.03.2018 / 18:40

1 answer

3

In version 6.2.2 the mapping is done via constructor, its mappings would look like this: DomainToViewModelMappingProfile:

public class DomainToViewModelMappingProfile : Profile
{
    public DomainToViewModelMappingProfile()
    {
        CreateMap<ClienteViewModel, Cliente>();
        CreateMap<ProdutoViewModel, Produto>();
    }
}

ViewModelToDomainMappingProfile:

public class ViewModelToDomainMappingProfile : Profile
{
    public ViewModelToDomainMappingProfile()
    {
        CreateMap<ClienteViewModel, Cliente>();
        CreateMap<ProdutoViewModel, Produto>();
    }
}

And the configuration class like this:

public class AutoMapperConfig
{

    public static void RegisterMappings()
    {

        Mapper.Initialize(x =>
        {
            x.AddProfile(new DomainToViewModelMappingProfile());
            x.AddProfile(new ViewModelToDomainMappingProfile());
        });

    }
}
    
20.03.2018 / 18:51