1

I've encountered a problem while upgrading from AutoMapper's static API.

I'm following the example on this page, which states that

Typical usage from 4.1 and before was:

Mapper.Initialize(cfg => {
     cfg.AddProfile<AppProfile>();
     cfg.CreateMap<Source, Dest>(); });

var dest = Mapper.Map<Source, Dest>(new Source());

In 4.2 and later, this would look like:

var config = new MapperConfiguration(cfg => {
     cfg.AddProfile<AppProfile>();
     cfg.CreateMap<Source, Dest>();
});

var mapper = config.CreateMapper();
var dest = mapper.Map<Source, Dest>(new Source());

However, while using v4.2.1 via NuGet I can't see this 'CreateMapper' method.

What am I supposed to use?

awj
  • 7,482
  • 10
  • 66
  • 120

1 Answers1

1

I've realised what was causing my problem.

In order to use the MapperConfiguration application-wide I was storing it as a static property:

public static IMapperConfiguration { get; private set; }

public static void Init()
{
    MapperConfiguration = new MapperConfiguration(...);
    ...
    MapperConfiguration.    // CreateMapper() not available
}

The problem here is that the CreateMapper method is only available on the MapperConfiguration class, not the IMapperConfiguration interface.

awj
  • 7,482
  • 10
  • 66
  • 120