在我的 Startup.cs
我的 ConfigureServices
中有一个 AutoMapper 配置文件方法:
AutoMapper.Mapper.Initialize(c => c.AddMaps(typeof(Models.MapperProfile), typeof(Data.Ef.MapperProfile)));
namespace Rm.Combo.Api.Models
{
public class MapperProfile : Profile
{
public MapperProfile()
{
CreateMap<NewCashoutModel, App.Cashouts.InitiateCashoutCommand>();
}
}
}
namespace Rm.Combo.Data.Ef
{
public class MapperProfile : Profile
{
public MapperProfile()
{
CreateMap<Domain.Cashouts.Cashout, Data.Cashouts.CashoutModel>();
}
}
}
自从我从版本
8.1.1
迁移以来,似乎有一定数量的重大变化到9.0.0
.我试图检查那些特定的链接:
但他们都没有说如何
最佳答案
从 9.0 开始,静态 API 不再可用。
您可以通过依赖注入(inject)使用 AutoMapper,如下所示:
1.安装 AutoMapper.Extensions.Microsoft.DependencyInjection
2.注册服务ConfigureServices
在 Startup.cs 上:
services.AddAutoMapper(typeof(MapperProfile));
引用:
How to using AutoMapper on ASP.NET Core via Dependency Injection
关于c# - 如何替换 AutoMapper 9.0 中的 `AutoMapper.Mapper.Initialize` 静态调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59274000/