Where to validate AutoMapper Configuration in ASP.Net Core application?

After digging around in the IMapper interface (and thanks to the documentation link provided by @LucianBargaoanu), I found exactly what I needed.

In ConfigureServices():

        // Adds AutoMapper to DI configuration and automagically scans the 
        // current assembly for any classes that inherit Profile 
        // and registers their configuration in AutoMapper
        services.AddAutoMapper();

The secret sauce is to add IMapper mapper as a parameter to Configure() – the parameter list is dependency-injected so you can reference any service registered in ConfigureServices()

public void Configure(IApplicationBuilder app, ... , IMapper mapper)
{
  ...
        mapper.ConfigurationProvider.AssertConfigurationIsValid();
}

Works exactly as expected.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)