how to inject a service inside an automapper profile in c#

Viewed 174

I am using AutoMapper profiles for mapping entities. In one of the mapping profiles I need to call a service method. I m trying to inject the service using profile constructor but then I m not able to register/add it. Any ideas how can I handle this?

public class HistoryProfile : Profile
{
    private readonly MappingService _mappingService;

    public HistoryProfile(MappingService mappingService)
    {
        _mappingService = mappingService;
        this.CreateMap<HistoryCHR, History>()
            .ForMember(h => h.BirthDate, hisChr => hisChr.MapFrom(x => x.DateOfBirth))
            .....................
     }
}



private static void InitializeSpecificProfiles()
    {
        Mapper.Initialize(
            cfg =>
            {                   
                cfg.AddProfile(new HistoryProfile());                    

            });
    }
0 Answers
Related