grokky
grokky

Reputation: 9255

Configuration of AutoMapper with ASP.NET Core

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

Answers (1)

grokky
grokky

Reputation: 9255

First one creates the instance on first request, second during bootup.

Upvotes: 4

Related Questions