Skip to content

Support LicenseKey via environment variable fallback#4634

Open
Nit8 wants to merge 1 commit intoLuckyPennySoftware:mainfrom
Nit8:main
Open

Support LicenseKey via environment variable fallback#4634
Nit8 wants to merge 1 commit intoLuckyPennySoftware:mainfrom
Nit8:main

Conversation

@Nit8
Copy link
Copy Markdown

@Nit8 Nit8 commented Apr 25, 2026

PR: Auto-Detect License Key from Environment Variables Fixes #4631

What Changed

Added support for reading the AutoMapper license key from an environment variable instead of requiring manual configuration in code.

Why

In containerized and cloud environments, it's better to use environment variables for sensitive configuration instead of hardcoding values in code.

How It Works

The LicenseKey property now checks for values in this order:

  1. Explicit value set in code (cfg.LicenseKey = "key") - highest priority
  2. Environment variable AUTOMAPPER_LICENSE_KEY - fallback
  3. Null if neither is set - lowest priority

Usage

NEW WAY - Using Environment Variable:
Set environment variable AUTOMAPPER_LICENSE_KEY before running your app
Then just add AutoMapper without setting the license key:

services.AddAutoMapper(cfg => 
{
    cfg.CreateMap<Foo, FooDto>();
});

OLD WAY - Still Works (Backward Compatible):

services.AddAutoMapper(cfg => 
{
    cfg.LicenseKey = "your-license-key";
    cfg.CreateMap<Foo, FooDto>();
});

BOTH SET - Code value wins:
If you set both the environment variable AND code value, the code value is used.

Tests Added

  • Tests for environment variable auto-detection
  • Tests for old explicit assignment (backward compatibility)
  • Tests for precedence when both are set
  • Integration tests with dependency injection

Backward Compatibility

100% backward compatible. All existing code continues to work exactly the same way.

LicenseKey now falls back to the AUTOMAPPER_LICENSE_KEY environment variable if not explicitly set. Added comprehensive unit and integration tests to verify this behavior. Updated test project dependencies to support DI and logging in tests.
@Nit8
Copy link
Copy Markdown
Author

Nit8 commented Apr 29, 2026

@jbogard can you run this pipeline to check if anything goes wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support automatic discovery of license keys

1 participant