-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DI behavior change between .NET 7.0 and .NET 8.0 #102888
Comments
#88968 was closed as by design and the change was documented. You'll need to share more details here.
If this was the case you'll need to add more details here to help us understand what you need. |
The breaking change doc is at dotnet/docs#36725. |
Yea, I saw this doc before. There is an issue: neither I nor Castle afais uses |
Castle uses IL.Emit which in v6 and earlier used to add a Closing this issue. A Castle bug should be created so it can be fixed for that. The fix would be to either add an empty constructor, or add default values to arguments via Running this below shows the behavior difference: var services = new ServiceCollection();
services.AddScopedWithInterceptors<ITestService, TestService, TestInterceptor>();
var b = services.BuildServiceProvider();
ServiceDescriptor sd = services[1];
// v6:
// Implementation type: ITestServiceProxy
// Orig Arg 1 serviceType False
// Impl Arg 1 True
// Orig Arg 2 serviceKey False
// Impl Arg 2 True
// Orig Arg 3 implementationType False
// Impl Arg 3 True
// v7+:
// Implementation type: ITestServiceProxy
// Orig Arg 1 serviceType False
// Impl Arg 1 False
// Orig Arg 2 serviceKey False
// Impl Arg 2 False
// Orig Arg 3 implementationType False
// Impl Arg 3 False
Console.WriteLine($"Implementation type: {sd.ImplementationType!.Name}");
Console.WriteLine($"Orig Arg 1 {sd.GetType().GetConstructors()[1].GetParameters()[0].Name} {sd.GetType().GetConstructors()[1].GetParameters()[0].HasDefaultValue}");
Console.WriteLine($"Impl Arg 1 {sd.ImplementationType.GetConstructors()[0].GetParameters()[0].Name} {sd.ImplementationType.GetConstructors()[0].GetParameters()[0].HasDefaultValue}");
Console.WriteLine($"Orig Arg 2 {sd.GetType().GetConstructors()[1].GetParameters()[1].Name} {sd.GetType().GetConstructors()[1].GetParameters()[1].HasDefaultValue}");
Console.WriteLine($"Impl Arg 2 {sd.ImplementationType.GetConstructors()[0].GetParameters()[1].Name} {sd.ImplementationType.GetConstructors()[0].GetParameters()[1].HasDefaultValue}");
Console.WriteLine($"Orig Arg 3 {sd.GetType().GetConstructors()[1].GetParameters()[2].Name} {sd.GetType().GetConstructors()[1].GetParameters()[2].HasDefaultValue}");
Console.WriteLine($"Impl Arg 3 {sd.ImplementationType.GetConstructors()[0].GetParameters()[2].Name} {sd.ImplementationType.GetConstructors()[0].GetParameters()[2].HasDefaultValue}");
var service = b.GetService<ITestService>();
System.Console.WriteLine(service.DoTest()); |
Description
Still have the issue on dotnet 8.
See #88968
Reproduction Steps
Reproduction repository: https://github.com/snowinmars/Dotnet8DiBugCase/tree/master
Expected behavior
See in the reproduction repository
Actual behavior
See in the reproduction repository
Regression?
No response
Known Workarounds
No response
Configuration
NET7 > NET8
Other information
No response
The text was updated successfully, but these errors were encountered: