c# - 在构造函数中使用 DI 的 automapper Ivalueresolver
问题描述
基本上我得到了相同的:Asp.net core 2.0 AutoMapper IValueResolver 依赖注入
但没有答案。
所以我得到了:
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
}
和想法?我在这个问题上遇到了无参数构造函数错误。
谢谢!
解决方案
推荐阅读
- ios - 麦克风在某些使用 maccatalist 的 Mac 设备上不起作用
- amazon-web-services - AWS Neptune DB 中的一对一关系
- powershell - 如何使用选项运行命令并将退出代码存储在变量中
- qt - 如何在 Qml 中更改视图?
- java - Apache Ignite 客户端无法与 Ignite 服务器连接(在不同的 VM 上)
- jenkins - Jenkins 错误 ImportError:没有名为 boto3 的模块
- flutter - chart_flutter :以千(K)、百万(M)为单位显示柱形图 Y 轴标签
- python - 如何从 Plotly 启动本地图表工作室实例
- tensorflow - 多头注意力层——什么是 Keras 中的 Warpper 多头层?
- session - 多用户会话管理