简体   繁体   中英

What is the alternative of "ResolveUsing" in AutoMapper.Extensions.Microsoft.DependencyInjection 6.0.0

I am working on .Net core 2.1 with AutoMapper.Extensions.Microsoft.DependencyInjection 6.0.0 . This is my mapping configuration :

CreateMap<User, UserForListDto>()
   .ForMember(dest => dest.Age, opt => {
       opt.ResolveUsing(d => d.DateOfBirth.CalculateAge());
});

Here ResolveUsing is not working, because it is removed or renamed in version 6.0.0 , but it works fine in version 4.0.1 .

I don't find any reference about the changes on their github . Can anybody tell me what is the alternative of ResolveUsing in version 6.0.0 ?

Issue created here

I got my answer. In the latest version, we don't need to ResolveUsing anymore. There is an overload added to MapFrom that serves the purpose of ResolveUsing .

// Old
CreateMap<User, UserForListDto>()
   .ForMember(dest => dest.Age, opt => {
       opt.ResolveUsing(d => d.DateOfBirth.CalculateAge());
});

// New
CreateMap<User, UserForListDto>()
   .ForMember(dest => dest.Age, opt => {
       opt.MapFrom(d => d.DateOfBirth.CalculateAge());
});

More details here

Simple replace ResolveUsing with MapFrom Error is kicked out.

        CreateMap<User, UserForListDto>()
                       .ForMember(dest => dest.PhotoUrl, opt => {
                           opt.MapFrom(src => src.Photos.FirstOrDefault(p => p.IsMain).Url);
                       }).ForMember(dest => dest.Age, opt => opt.MapFrom(d => (DateTime.Now - d.DateOfBirth).TotalDays / 365));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM