我正在使用带有内置容器的 ASP.NET Core。
自动注册完成like so :
var config = new MapperConfiguration(c => c.AddProfiles(typeof(Startup)));
services.AddSingleton<IMapper>(s => config.CreateMapper());
这会自动 1) 配置 AutoMapper,以及 2) 注册在程序集中找到的所有配置文件。
但我想手动注册我的个人资料。我该怎么做?
最佳答案
只需使用该方法的sigular 版本。
var config = new MapperConfiguration(c => {
c.AddProfile<ProfileA>();
c.AddProfile<ProfileB>();
});
services.AddSingleton<IMapper>(s => config.CreateMapper());
关于c# - 如何在 ASP.NET Core 中手动注册 AutoMapper 配置文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42297173/