尝试将AutoMapper添加到.NetCore1.1-无法识别服务. [英] Trying to add AutoMapper to .NetCore1.1 - not recognising services.AddAutoMapper()

查看:36
本文介绍了尝试将AutoMapper添加到.NetCore1.1-无法识别服务.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在项目中安装了以下Nuget软件包:

I've installed the following Nuget packages into my project:

  • Automapper
  • AutoMapper.Extensions.Microsoft.DependencyInjection

我已将行添加到 Startup.cs 中的 ConfigureServices 中.

I have added the line to ConfigureServices in Startup.cs.

public void ConfigureServices(IServiceCollection services)
{
    // Add framework services.
    services.AddMvc();
    // . . .
    services.AddAutoMapper();
}

services.AddAutoMapper()下,我仍然出现红线.它说:

I'm still getting a red line under services.AddAutoMapper(). It says:

以下方法或属性之间的调用不明确:ServiceCollectionExtensions.AddAutoMapper(IServiceCollection,params Assembly [])和ServiceCollectionExtensions.AddAutoMapper(IServiceCollection,params Type [])

The Call is ambiguous between the following methods or properties: ServiceCollectionExtensions.AddAutoMapper(IServiceCollection, params Assembly[]) and ServiceCollectionExtensions.AddAutoMapper(IServiceCollection, params Type[])

为什么会这样?我读过的所有.NET Core添加自动映射器指南都显示了这样做的方法.

Why is this happening? All the .NET Core add automapper guides I've read show to do it this way.

推荐答案

我遇到了同样的问题,因此检查了 Profile 类与 Startup 类在同一程序集中.

I'm running into the same issue, so checked the sourcecode and tests for guidance. It seems you need to pass either an assembly or a "marker type" inside the assembly you want scanned. I went for the following as my Profile classes are in the same assembly as the Startup class.

services.AddAutoMapper(typeof(Startup));

这篇关于尝试将AutoMapper添加到.NetCore1.1-无法识别服务.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆