Skip to content

Commit 5295367

Browse files
Copilotjbogard
andcommitted
docs: document fixes for multiple license messages
Co-authored-by: jbogard <104498+jbogard@users.noreply.github.com>
1 parent 0591466 commit 5295367

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

docs/source/License-configuration.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,47 @@ There is no other license enforcement besides log messages. No central license s
3030

3131
The log messages are logged using standard `Microsoft.Extensions.Logging` loggers under the category name `LuckyPennySoftware.AutoMapper.License`.
3232

33+
### Multiple License Messages
34+
35+
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.
36+
37+
#### Using `AddAutoMapper` (Microsoft.Extensions.DependencyInjection)
38+
39+
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:
40+
41+
```c#
42+
services.AddAutoMapper(cfg => { cfg.LicenseKey = "key"; });
43+
services.AddAutoMapper(cfg => { /* ignored -- IMapper already registered */ });
44+
```
45+
46+
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.
47+
48+
#### Using `MapperConfiguration` Directly
49+
50+
When creating `MapperConfiguration` instances manually, each instance performs its own license validation, producing a separate log message:
51+
52+
```c#
53+
// Each of these logs a license message – avoid creating multiple instances
54+
var config1 = new MapperConfiguration(cfg => { cfg.LicenseKey = "key"; }, loggerFactory);
55+
var config2 = new MapperConfiguration(cfg => { cfg.LicenseKey = "key"; }, loggerFactory);
56+
```
57+
58+
To avoid duplicate messages, create and reuse a single `MapperConfiguration` instance for the lifetime of your application, typically registered as a singleton:
59+
60+
```c#
61+
// Create once and reuse
62+
var config = new MapperConfiguration(cfg => { cfg.LicenseKey = "key"; }, loggerFactory);
63+
var mapper = new Mapper(config);
64+
```
65+
66+
#### Suppressing Duplicate License Messages
67+
68+
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:
69+
70+
```csharp
71+
builder.Logging.AddFilter("LuckyPennySoftware.AutoMapper.License", LogLevel.None);
72+
```
73+
3374
### Client Redistribution Scenarios
3475

3576
In the case where AutoMapper is used on a client, including:

0 commit comments

Comments
 (0)