I try to use AutoMapper in my .Net Core 2.0 Console Application. My class looks like this:
public class AutoGetCurrency
{
private readonly IMapper mapper;
public AutoGetCurrency(IMapper mapper) {
this.mapper = mapper;
}
....
}
I tried to add services into Main method:
static void Main(string[] args)
{
var services = new ServiceCollection();
ServiceProvider = services.BuildServiceProvider();
services.AddTransient<IMapper>();
....
}
But I have the next error 'One or more errors occurred. (Object reference not set to an instance of an object.)'
Please tell me how to add AutoMapper to use DI.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…