-
Couldn't load subscription status.
- Fork 311
Make TService type param more permissive on Add*<TService, TImplementation>() #624
Conversation
|
Will add tests after feedback (if this is a genuine issue) |
|
Is this a breaking change? |
|
Not entirely sure. Superficially I don't think so! I wouldn't have thought -- seeing as this is making it more permissive on the constraints -- but there may be some way you could write something where it would break something that worked previously using reflection/inline IL?? |
|
Okay, it's been picked up as a breaking change - but is it really? This is a strange one as it clearly works when not passing template params. What's different between this invocation public static IServiceCollection RegisterScopedTestService<TService, TImplementation>(this IServiceCollection services)
where TImplementation : class, TService
{
return services.AddScoped<TService, TImplementation>();
}and this one public void SomeFunction(IServiceCollection services)
{
services.AddScoped<ITestService, TestService>();
}given public interface ITestService
{
}
public class TestService : ITestService
{
}The signature still expects |
|
You just need to add |
|
Just realised that! 😄 Now I'm wondering if the constraint is actually required. Under what circumstances could you register something which fails these constraints TService : class
TImplementation : TService, classbut passes with these //TService : any
TImplementation : TService, class |
It may not be possible but I'm not sure it matters because we wouldn't make a breaking change like this regardless. |
|
interesting. I'll post on SO, see if anyone can out of curiosity. Very understandable! Thanks 😄 |
|
So after a little reading it would seem that the current definition is more technically correct, even if it's not necessary. I suspect the choice was taken to have both constraints there as it clearly shows that TService must be a reference type! |
|
https://stackoverflow.com/a/48471755/3515174 Brilliant insight here 😄 |
Fixes dotnet/aspnetcore#2828