Skip to main content

EXMIG0001: MediatR registration is portable to Excalibur.Dispatch

PropertyValue
Diagnostic IDEXMIG0001
TitleMediatR registration is portable to Excalibur.Dispatch
CategoryMigration
SeverityInfo
Enabled by defaultYes
Code-fixYes

Cause

The analyzer found a MediatR dependency-injection registration call (services.AddMediatR(...)). This call maps directly onto the Excalibur.Dispatch compat registration entry point AddMediatRCompat(...) as part of migrating off the now-commercial MediatR package.

Detection is syntax-based on the invoked method name, so the diagnostic fires whether or not the MediatR assembly is still referenced — the realistic state of code mid-migration.

Example

The following code triggers EXMIG0001:

// Info EXMIG0001: 'AddMediatR' can be mechanically migrated to 'AddMediatRCompat(...)'
builder.Services.AddMediatR(cfg =>
cfg.RegisterServicesFromAssembly(typeof(Program).Assembly));

How to Fix

Apply the code-fix, or edit manually. The rewrite preserves the assembly-scan arguments:

builder.Services.AddMediatRCompat(cfg =>
cfg.RegisterServicesFromAssembly(typeof(Program).Assembly));

AddMediatRCompat self-bootstraps the Dispatch core (AddDispatch(), idempotent) and validates its options at startup. See Migrating from MediatR — drop-in shim.

When to Suppress

Suppress while both frameworks intentionally run side by side and you are not yet ready to migrate a given registration:

#pragma warning disable EXMIG0001
builder.Services.AddMediatR(/* ... */);
#pragma warning restore EXMIG0001

See Also