0

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?

2
  • 1
    First one creates the instance on first request, second during bootup Commented Nov 6, 2016 at 21:07
  • @Tseng Please add as answer so I can accept? Commented Nov 6, 2016 at 21:32

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.