1

Basically I got the same as: Asp.net core 2.0 AutoMapper IValueResolver dependency injection

but there was no answer.

So i got:

public static void AddMapperConfiguration(this IServiceCollection services)
{
    var spb = services.BuildServiceProvider();

    var mapperConfiguration = new MapperConfiguration(cfg =>
    {
        cfg.AddProfile<CmsDataMappingProfile>();
        cfg.AddProfile<ClsMappingProfile>();
        cfg.AddProfile<ClsMockDataMappingProfile>();
        cfg.AddProfile<LpisMappingProfile>();

        cfg.AllowNullCollections = true;
        cfg.AllowNullDestinationValues = true;
        cfg.ConstructServicesUsing(spb.GetService); //read it the other post
    });

    mapperConfiguration.AssertConfigurationIsValid();
    services.AddSingleton<IMapper>(sp => new Mapper(mapperConfiguration)); //just testing
}

and as resolver:

public class CurrencyResolver : IValueResolver<List<VehicleAndQuote>, LeasingPlan, List<Duration>>
{
    private readonly ICountryProfileConnector _countryProfileConnector;

    public CurrencyResolver(ICountryProfileConnector countryProfileConnector)
    {
        _countryProfileConnector = countryProfileConnector;
    }

     ....left out for readability
}

and thoughts? I'm getting the no parameterless constructor error on this.

thnx!

vahdet
  • 6,357
  • 9
  • 51
  • 106
Roelant M
  • 1,581
  • 1
  • 13
  • 28
  • https://github.com/AutoMapper/AutoMapper.Extensions.Microsoft.DependencyInjection – Lucian Bargaoanu Jul 24 '18 at 15:02
  • the post is long and i was missing some information. Turns out only `services.AddAutoMapper()` does the trick. Thnx. However, now i am getting an error on one of the nested mapping. it was like `... .ForMember(catalogVehicle => catalogVehicle.VehicleSpecification, src => src.MapFrom(vehicleAndQuote => vehicleAndQuote));` and then in the profile i've `CreateMap()..formembers etc..` is that changed? – Roelant M Jul 24 '18 at 20:42
  • Make sure you pass types or assemblies to AddAutomapper. And also that you inject IMapper, not use the static Mapper. – Lucian Bargaoanu Jul 25 '18 at 04:11

0 Answers0