Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I validate configuration with the automapper Instance API

Tags:

c#

automapper

I know that using automapper's static API I can do this:

Mapper.Initialize(cfg => 
  cfg.CreateMap<Source, Destination>());

Mapper.Configuration.AssertConfigurationIsValid();

but now I've switched to the instance API:

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

var mapper = config.CreateMapper();

How/where can I check if the configuration is valid using the instance API?

like image 403
John M Avatar asked May 31 '17 13:05

John M


People also ask

Where is AutoMapper configuration?

Where do I configure AutoMapper? ¶ Configuration should only happen once per AppDomain. That means the best place to put the configuration code is in application startup, such as the Global.

What is AutoMapper configuration?

What is AutoMapper? AutoMapper is a simple library that helps us to transform one object type into another. It is a convention-based object-to-object mapper that requires very little configuration. The object-to-object mapping works by transforming an input object of one type into an output object of a different type.

Should AutoMapper be tested?

One of the inspirations behind AutoMapper was to eliminate not just the custom mapping code, but eliminate the need for manual testing. Because the mapping from source to destination is convention-based, you will still need to test your configuration.


1 Answers

You can also do the validation using:

mapper.ConfigurationProvider.AssertConfigurationIsValid();
like image 96
L. Charlebois Avatar answered Oct 10 '22 07:10

L. Charlebois