-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
not support keyed services when use scoped service #90235
Comments
Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection Issue DetailsDescriptionWhen trying to use the keyed service with scoped lifetime, Reproduction Stepsvar serviceCollection = new ServiceCollection();
serviceCollection.AddKeyedScoped<IIdGenerator, GuidIdGenerator>("guid");
using var services = serviceCollection.BuildServiceProvider();
using var scope = services.CreateScope();
var newId = scope.ServiceProvider.GetRequiredKeyedService<IIdGenerator>("guid")
.NewId();
Console.WriteLine(newId);
file interface IIdGenerator
{
string NewId();
}
file sealed class GuidIdGenerator : IIdGenerator
{
public string NewId() => Guid.NewGuid().ToString("N");
} Expected behaviorOutput a Guid value without exception Actual behaviorException with the stack trace below
Regression?No response Known WorkaroundsNo response Configuration.NET 8 Preview 7, 8.0.100-preview.7.23376.3 Other informationNo response
|
Seemed already fixed by #89509 closed |
Description
When trying to use the keyed service with scoped lifetime,
InvalidOperationException
thrown withThis service provider doesn't support keyed services
messageReproduction Steps
Expected behavior
Output a Guid value without exception
Actual behavior
Exception with the stack trace below
Regression?
No response
Known Workarounds
No response
Configuration
.NET 8 Preview 7, 8.0.100-preview.7.23376.3
Windows 11 x64
Other information
No response
The text was updated successfully, but these errors were encountered: