Reputation: 9255
In ASP.NET Core, AutoMapper is now configured like this (in Startup.ConfigureServices
):
var config = new MapperConfiguration(cfg => {
cfg.AddProfile(new MyConfig());
});
services.AddSingleton<IMapper>(sp => config.CreateMapper());
Why not the following:
var config = new MapperConfiguration(cfg => {
cfg.AddProfile(new MyConfig());
});
var mapper = config.CreateMapper();
services.AddSingleton(mapper);
Is there a difference? Something to do with lazy loading maybe?
Upvotes: 0
Views: 1306
Reputation: 9255
First one creates the instance on first request, second during bootup.
Upvotes: 4