基本上,我得到的是:Asp.net core 2.0 AutoMapper IValueResolver dependency injection
但是没有答案。
所以我得到了:
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
}
并作为解析器:
public class CurrencyResolver : IValueResolver<List<VehicleAndQuote>, LeasingPlan, List<Duration>>
{
private readonly ICountryProfileConnector _countryProfileConnector;
public CurrencyResolver(ICountryProfileConnector countryProfileConnector)
{
_countryProfileConnector = countryProfileConnector;
}
....left out for readability
}
和想法?我遇到了无参数构造函数错误。
thnx!