I need to use a service layer in the AutoMapper
profile class in ASP.NET Core
but when I inject service in the constructor it does not work. For example:
public class UserProfile : Profile
{
private readonly IUserManager _userManager;
public UserProfile(IUserManager userManager)
{
_userManager = userManager;
CreateMap<User, UserViewModel>()
.ForMember(dest => dest.FullName, opt => opt.MapFrom(src => $"{src.FirstName} {src.LastName}"));
}
}
And in Startup
Class:
public class Startup
{
public IConfigurationRoot Configuration { set; get; }
public Startup(IHostingEnvironment env)
{
//some code
}
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
services.AddMvc();
services.AddScoped<IUsersPhotoService, UsersPhotoService>();
services.AddAutoMapper(typeof(UserProfile));
}
}
How do to do it?
question from:https://stackoverflow.com/questions/44877379/how-inject-service-in-automapper-profile-class