Skip to content

Upgrade to MediatR 3.0 #1694

@mgmccarthy

Description

@mgmccarthy

cc @tonysurma @dpaquette @stevejgordon @MisterJames

I've been doing some research into what it will take to upgrade the project to MediatR 3.0. There are breaking API changes that cause a lot of code to have to change, plus an annoying default parameter that was added to each method on IMediator which makes any mocked call to .Send or Publish non-compilable in our unit tests.

Here is what we get with version 3.0 of MediatR:

Here is a list of what needs to be done:

  • upgrade MediatR NuGet package to version 3.0
  • track down, and change all instances of .SendAsync to .Send
  • track down, and change all instances of .PublishAsync to .Publish
  • track down and change all instances of IAsyncRequest with IRequest (use match whole word on this one for find/replace b/c we do not want to change the name of IAsyncRequestHandler)
  • track down and change all instances of IAsyncNotification with INotification (use match whole word on find/replace)
  • track down and change all instances of AsyncRequestHandler with IAsyncRequestHandler (AsyncRequestHandler has been deprecated). This change gets rid of the weird protected override void HandleCore signature on command handlers that don't return a value
  • as a result of the AsyncRequestHandler to IAsyncRequestHandler refactoring, change all instances of protected override async Task HandleCore to public async Task Handle.
  • all calls to mediator interface needs to be updated to be awaitable
  • and the big one, append, , default(CancellationToken) onto any mocked call to .Send or .Publish in our unit tests.

All of the above changes are easily achievable using Visual Studio Find and Replace except for item 7. For item 7, I've written a file/string parser that will go through and append , default(CancellationToken) to any mocked call to .Send or .Publish. I'm still testing it locally, but have already had successful replacements on unit test and those tests have compiled and run successfully.

Anything that's left over can be easily fixed by hand.

Between the breaking API changes and some of the more nitty-gritty test code changes that need to take place (items 6 and 7), we're looking at changes over at least 75% of the codebase.

So most likely, this upgrade will need to be part of some type of PR merging "freeze" so this one, massive PR can hit the system and be merged.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions