"The non-generic method 'IServiceProvider.GetService(Type)' cannot be used with type arguments

Adding using Microsoft.Extensions.DependencyInjection manually helped me.

Also you might want to consider using .GetRequiredService<>() which throws an Exception if the service is not registered, which might help better debug.

Also, although you can still use IMediator, you might want to consider using ISender to be more strict about it.