AspnetCore DI and contravariant fun
See original GitHub issueThis 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:
- Created 4 years ago
- Comments:29 (15 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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?
Yeah, I think I’ll put this in the back burner for now. Maybe in C# 42?