Should IStringLocalizer be covariant?
See original GitHub issueLike ILogger<T>
, IOptions<T>
or IOptionsMonitor<T>
, should IStringLocalizer<T>
be covariant? This would allow this kind of pattern:
public class Base
{
public Base(IStringLocalizer<Base> localizer) { }
}
public class Derived : Base
{
public Base(IStringLocalizer<Derived> localizer)
: base(localizer) { }
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Should IStringLocalizer be covariant? · Issue #975
@davidfowl thoughts? I feel like making it covariant only makes sense if we actually walk the class inheritance tree as part of class ......
Read more >c# - How dependency injection work for covariance type in ...
You could check the source code for ILogger by Logging. Here is the process. For ILogger<AController> , it is crated by LoggerFactoryExtensions
Read more >Covariance and Contravariance in Generics
Covariance. Enables you to use a more derived type than originally specified. You can assign an instance of IEnumerable<Derived> to a ...
Read more >Introducing C# 9: Covariant returns
In this article I will show you how it works with a very simple example and ... Here is a simple example of...
Read more >Practical usage of C# covariance
Variance is a .NET 4.0 concept that allows implicit conversion between instances of generic types. In other words, it permits the ...
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
Excellent, I’ll send a PR soon, then 😄
Yeah, the main scenario I have in mind is to allow an application to override the resources location when subclassing a class from a class library that comes with
.resx
files and uses[assembly: ResourceLocation("...")]
.It’s exactly like how options and generic loggers work:
It’s something I use in OpenIddict: I have a
OpenIddictServerOptions
class that inherits fromOpenIdConnectServerOptions
(from ASOS) and defines additional options. WhereverIOptionsMonitor<OpenIdConnectServerOptions>
is used, I simply flowIOptionsMonitor<OpenIddictServerOptions>
(e.g https://github.com/openiddict/openiddict-core/blob/dev/src/OpenIddict.Server/OpenIddictServerHandler.cs#L25).