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 ex
I get it that this question is not recent but there is a nuget package for this: AutoMapperBuilder.
You can get what you want by replacing this line:
services.AddAutoMapper(typeof(UserProfile));
with these:
services.AddAutoMapperBuilder(builder =>
{
builder.Profiles.Add(new UserProfile(services.BuildServiceProvider().GetRequiredService()));
});