C# 如何替换AutoMapper 9.0中的'AutoMapper.Mapper.Initialize'静态调用?

C# 如何替换AutoMapper 9.0中的'AutoMapper.Mapper.Initialize'静态调用?,c#,asp.net-core,.net-core,automapper,C#,Asp.net Core,.net Core,Automapper,在我的Startup.cs文件中,我的ConfigureServices方法中有一个AutoMapper配置: AutoMapper.Mapper.Initialize(c=>c.AddMaps(typeof(Models.MapperProfile),typeof(Data.Ef.MapperProfile)); 名称空间Rm.Combo.Api.Models { 公共类MapperProfile:Profile { 公共MapperProfile() { CreateMap(); } }

在我的
Startup.cs
文件中,我的
ConfigureServices
方法中有一个AutoMapper配置:

AutoMapper.Mapper.Initialize(c=>c.AddMaps(typeof(Models.MapperProfile),typeof(Data.Ef.MapperProfile));
名称空间Rm.Combo.Api.Models
{
公共类MapperProfile:Profile
{
公共MapperProfile()
{
CreateMap();
}
}
}
名称空间Rm.Combo.Data.Ef
{
公共类MapperProfile:Profile
{
公共MapperProfile()
{
CreateMap();
}
}
}
自从我从版本
8.1.1
升级到
9.0.0
以来,似乎有一些突破性的变化

我试图检查这些特定链接:


但是没有人说如何从9.0开始,静态API不再可用

您可以通过依赖项注入使用AutoMapper,如下所示:

1.安装

2.在启动时在
ConfigureServices
中注册服务。cs:

services.AddAutoMapper(typeof(MapperProfile));
参考: