小编Col*_*ber的帖子

具有依赖注入的 AutoMapper 不映射配置文件?

所以这是我的第一个 Stack Overflow 问题,我希望我能提供足够的帮助细节。我正在尝试将 AutoMappper 与 dotnet 3.1 与依赖注入一起使用,但是它似乎并没有像它所说的那样注册我的地图。

我收到的错误:

AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.

Mapping types:
User -> UserCustomerDto
Run Code Online (Sandbox Code Playgroud)

在我的 Startup.cs 中,我有:services.AddAutoMapper(typeof(Startup));在该区IServiceCollection域内

User创建了我的模型和各种 DTO 模型。

这是我拥有的示例 Profile 模型:

AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.

Mapping types:
User -> UserCustomerDto
Run Code Online (Sandbox Code Playgroud)

我的 DTO 模型具有我的用户模型所具有的所有字段,但我不想显示在 UI 中的那些字段。

文档相当难以遵循,因为有非依赖注入的示例以及在项目启动期间需要配置的 9.0 之前的示例。

我也尝试.ReverseMap()在 上使用,CreateMap()但这也不起作用。

我正在使用的服务中注入:

    public class UserCustomerProfile : Profile
    {
        public UserCustomerProfile()
        {
            CreateMap<User, UserCustomerDto>();
            CreateMap<UserCustomerDto, User>();
        } …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework dependency-injection automapper asp.net-core

3
推荐指数
1
解决办法
2450
查看次数