License Key Configuration - LuckyPennySoftware/MediatR GitHub Wiki
MediatR is dual licensed. To configure the commercial license, either the license key can be set using Microsoft.Extensions.DependencyInjection integration:
services.AddMediatR(cfg => {
cfg.LicenseKey = "License key here";
// Other configuration
});
Or on non-MS.Ext.DI scenarios, where you're configuring a 3rd-party container directly, you can set the license key with a static property:
Mediator.LicenseKey = "License key here";
You can obtain a valid license from the MediatR website.
License Enforcement
Licensing is enforced via log messages at various levels:
- INFO: Valid license message
- WARNING: Missing license message
- ERROR: Invalid/expired license message
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.MediatR.License.
Client Redistribution Scenarios
In the case where MediatR is used on a client, including:
- Blazor WASM
- WPF/MAUI/Desktop apps
- Redistributed clients
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.MediatR.License", LogLevel.None);
This will depend on your logging setup. A missing/invalid license key does not affect runtime behavior in any way.
Auto-discovery via environment variables
If no license key is set in code, MediatR looks for one in environment variables. This is convenient for containerized and cloud environments, and for enterprises that share a single key across many services without code changes:
MEDIATR_LICENSE_KEY– the MediatR-specific license key.LUCKYPENNY_LICENSE_KEY– a shared key usable across Lucky Penny products (for example, AutoMapper reads the same variable). Because it is shared, the key must be for a license that includes MediatR (aBundleor MediatR edition); an AutoMapper-only license will not validate here.
The license key is resolved in the following order of precedence, using the first value found:
- An explicit value set in code (
cfg.LicenseKeyorMediator.LicenseKey). - The
MEDIATR_LICENSE_KEYenvironment variable. - The
LUCKYPENNY_LICENSE_KEYenvironment variable.
No code change is required when using an environment variable—just register MediatR as usual without setting the license key.
You can register for your license key at MediatR.io