docs/source/License-configuration.md
AutoMapper is dual licensed. To configure the commercial license, either the license key can be set using Microsoft.Extensions.DependencyInjection integration:
services.AddAutoMapper(cfg => {
cfg.LicenseKey = "License key here";
// Other configuration
});
Or on non-MS.Ext.DI scenarios, where you're using AutoMapper directly, you can set the license key in the constructor for the MappingConfiguration:
var mapperConfiguration = new MapperConfiguration(cfg => {
cfg.LicenseKey = "License Key Here";
}, loggerFactory);
You can obtain a valid license from the AutoMapper website.
Licensing is enforced via log messages at various levels:
There is no other license enforcement besides log messages. No central license server, no outbound HTTP calls, no degrading or disabling of features.
The log messages are logged using standard Microsoft.Extensions.Logging loggers under the category name LuckyPennySoftware.AutoMapper.License.
If you see duplicate license log messages at startup, this is typically caused by AutoMapper being registered or configured more than once in your application.
AddAutoMapper (Microsoft.Extensions.DependencyInjection)Calling AddAutoMapper multiple times in the same IServiceCollection is safe. After the first call registers IMapper, subsequent calls are ignored and no additional license validation occurs:
services.AddAutoMapper(cfg => { cfg.LicenseKey = "key"; });
services.AddAutoMapper(cfg => { /* ignored -- IMapper already registered */ });
If you are calling AddAutoMapper in multiple places (e.g. in modular startup code), each call still only results in a single MapperConfiguration singleton and a single license log message.
MapperConfiguration DirectlyWhen creating MapperConfiguration instances manually, each instance performs its own license validation, producing a separate log message:
// Each of these logs a license message – avoid creating multiple instances
var config1 = new MapperConfiguration(cfg => { cfg.LicenseKey = "key"; }, loggerFactory);
var config2 = new MapperConfiguration(cfg => { cfg.LicenseKey = "key"; }, loggerFactory);
To avoid duplicate messages, create and reuse a single MapperConfiguration instance for the lifetime of your application, typically registered as a singleton:
// Create once and reuse
var config = new MapperConfiguration(cfg => { cfg.LicenseKey = "key"; }, loggerFactory);
var mapper = new Mapper(config);
If you intentionally have multiple configurations (for example in integration tests or modular scenarios), you can silence duplicate license log messages by filtering the log category:
builder.Logging.AddFilter("LuckyPennySoftware.AutoMapper.License", LogLevel.None);
In the case where AutoMapper is used on a client, including:
The license key should NOT be set as this would result in secrets transmitted to the client. Instead, omit the license key configuration and mute the license message category name using:
builder.Logging.AddFilter("LuckyPennySoftware.AutoMapper.License", LogLevel.None);
This will depend on your logging setup. A missing/invalid license key does not affect runtime behavior in any way.