Skip to content

Migrate MediatR integration to Mediator#928

Merged
neozhu merged 23 commits intomainfrom
migrate-mediatr-to-mediator-main
Mar 29, 2026
Merged

Migrate MediatR integration to Mediator#928
neozhu merged 23 commits intomainfrom
migrate-mediatr-to-mediator-main

Conversation

@neozhu
Copy link
Copy Markdown
Owner

@neozhu neozhu commented Mar 29, 2026

Summary

  • replace repository MediatR usage with Mediator.Abstractions and wire runtime registration through Mediator.SourceGenerator
  • preserve scoped mediator and notification publishing behavior, and remove duplicate pipeline registration during the migration
  • add migration design/plan docs and expand unit/integration safety-net coverage for mediator runtime behavior

Test Plan

  • dotnet test tests/Application.UnitTests/Application.UnitTests.csproj -v minimal -p:UseSharedCompilation=false
  • dotnet test tests/Application.IntegrationTests/Application.IntegrationTests.csproj --filter FullyQualifiedName~MediatorCompatibilityTests -v minimal -p:UseSharedCompilation=false
  • manual verification completed locally

neozhu added 23 commits March 29, 2026 14:16
…iatr-to-mediator-main

# Conflicts:
#	docs/superpowers/plans/2026-03-29-migrate-mediatr-to-mediator.md
#	docs/superpowers/specs/2026-03-29-migrate-mediatr-to-mediator-design.md
#	tests/Application.IntegrationTests/Common/MediatorCompatibility/MediatorCompatibilityTests.cs
#	tests/Application.UnitTests/Common/MediatorCompatibility/ParallelNoWaitPublisherTests.cs
#	tests/Application.UnitTests/Infrastructure/MediatorCompatibility/ScopedMediatorTests.cs
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud


if (request is PingQuery)
{
return new ValueTask<TResponse>((TResponse)(object)"pong");

Check warning

Code scanning / CodeQL

Useless upcast Warning test

There is no need to upcast from
String
to
Object
- the conversion can be done implicitly.

Copilot Autofix

AI 21 days ago

In general, to fix a “Useless upcast” warning, you remove the unnecessary explicit cast and rely on C#’s implicit conversion from the expression’s type to the target type. This keeps the code simpler and clearer, without changing runtime behavior.

Here, the method Send<TResponse>(IRequest<TResponse> request, ...) returns ValueTask<TResponse>. When the request is a PingQuery, it currently returns new ValueTask<TResponse>((TResponse)(object)"pong"). The inner (object) cast is the useless upcast: "pong" is a string, which already implicitly converts to object. The outer (TResponse) cast is still needed to satisfy the generic return type in this fake/test implementation. So the best fix, without changing any behavior or public surface, is to remove only the (object) cast and leave (TResponse)"pong".

Concretely:

  • In tests/Application.UnitTests/Infrastructure/MediatorCompatibility/ScopedMediatorTests.cs, within the FakeMediator.Send<TResponse>(IRequest<TResponse> request, ...) method, edit line 110 to change ((TResponse)(object)"pong") to ((TResponse)"pong").
  • No new methods, imports, or definitions are required.
Suggested changeset 1
tests/Application.UnitTests/Infrastructure/MediatorCompatibility/ScopedMediatorTests.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/tests/Application.UnitTests/Infrastructure/MediatorCompatibility/ScopedMediatorTests.cs b/tests/Application.UnitTests/Infrastructure/MediatorCompatibility/ScopedMediatorTests.cs
--- a/tests/Application.UnitTests/Infrastructure/MediatorCompatibility/ScopedMediatorTests.cs
+++ b/tests/Application.UnitTests/Infrastructure/MediatorCompatibility/ScopedMediatorTests.cs
@@ -107,7 +107,7 @@
 
             if (request is PingQuery)
             {
-                return new ValueTask<TResponse>((TResponse)(object)"pong");
+                return new ValueTask<TResponse>((TResponse)"pong");
             }
 
             throw new NotSupportedException($"Unexpected request type: {request.GetType().Name}");
EOF
@@ -107,7 +107,7 @@

if (request is PingQuery)
{
return new ValueTask<TResponse>((TResponse)(object)"pong");
return new ValueTask<TResponse>((TResponse)"pong");
}

throw new NotSupportedException($"Unexpected request type: {request.GetType().Name}");
Copilot is powered by AI and may make mistakes. Always verify output.
@neozhu neozhu merged commit fa8890d into main Mar 29, 2026
4 of 5 checks passed
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.

2 participants