question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AspnetCore DI and contravariant fun

See original GitHub issue

This line is the bane of my existence 😉 https://github.com/jbogard/MediatR/blob/master/src/MediatR/Mediator.cs#L35

Could we not do another major version bump and update IMediator.Send to be

        Task<TResponse> Send<TRequest, TResponse>(
            TRequest request,
            CancellationToken cancellationToken = default (CancellationToken))
            where TRequest : IRequest<TResponse>;

In that case we at least have some way of forcing MediatR to fetch the correct type from the container by casting it beforehand.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:29 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
jbogardcommented, Apr 15, 2019

Why not open a PR to fix that? They’re suuuuuuuper receptive about adding valuable features to core DI.

Or use a container that does support variance?

1reaction
jbogardcommented, May 2, 2019

Yeah, I think I’ll put this in the back burner for now. Maybe in C# 42?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Constrained Open Generics Support Merged in .NET Core ...
Notice the contravariance here - we can use more derived types in the T parameter. I often do this in validation when I...
Read more >
c# - Microsoft Dependency injection and contravariance
I'm porting a library to net core. We now have the built in DI and I want to use it has best as...
Read more >
Dependency injection in ASP.NET Core
ASP.NET Core supports the dependency injection (DI) software design pattern, which is a technique for achieving Inversion of Control (IoC) ...
Read more >
Adding decorated classes to the ASP.NET Core DI ...
In this post I show how to do service decoration with Scrutor, where services "wrap" another implementation of the service.
Read more >
Advanced Dependency Injection Techniques in ASP.NET ...
NET Core dependency injection techniques that are present in many complex projects but go beyond the standard DI usage patterns.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found