Home > Software engineering >  How to setup AutoMapper in ASP.Net Core 6
How to setup AutoMapper in ASP.Net Core 6

Time:02-23

How to configure AutoMapper in ASP.Net Core 6

I have a project which is written in .Net 3.1 so we had Startup.cs class.

I am migrating it to .net core 6

now when I put the following configuration in my .Net 6 Program.cs

             builder.Services.AddAutoMapper(typeof(Startup));

I get error the type or namespace Startup could not be found

Any suggestions ?, how can I fix it or configure it in .net 6

CodePudding user response:

Using this line instead: typeof(Program).Assembly

CodePudding user response:

Install AutoMapper Package(version as per your proj requirement)

Install-Package AutoMapper.Extensions.Microsoft.DependencyInjection -Version 9.0.0

after that register a service in CinfigureServices on Startup.cs

using AutoMapper;
public void ConfigureServices(IServiceCollection services){
    services.AddAutoMapper(typeof(Startup));
}
  • Related