2 回答

TA貢獻(xiàn)1776條經(jīng)驗(yàn) 獲得超12個(gè)贊
在使用 DI 注冊(cè)自動(dòng)映射器時(shí),您需要使用映射所在程序集中的類型。
AddAutomapper(typeof(ViewModelToEntityProfile));
如果您有多個(gè)帶有地圖的程序集 - 您可以使用另一個(gè)重載:
AddAutomapper(typeof(ViewModelToEntityProfile), typeof(SomeOtherTypeInOtherAssembly));

TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超13個(gè)贊
Startup.cs創(chuàng)建映射配置類后,您需要在如下所示中添加 AutoMapperConfiguration :
public void ConfigureServices(IServiceCollection services) {
// .... Ignore code before this
// Auto Mapper Configurations
var mappingConfig = new MapperConfiguration(mc =>
{
mc.AddProfile(new ViewModelToEntityProfile());
});
IMapper mapper = mappingConfig.CreateMapper();
services.AddSingleton(mapper);
services.AddMvc();
}
- 2 回答
- 0 關(guān)注
- 179 瀏覽
添加回答
舉報(bào)