-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Unable to inject IKeyedServiceProvider into service with .NET 8 Preview 7 #90528
Comments
Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection Issue DetailsDescriptionThe update to dependency injection to allow for Keyed Services really interested me so I had a play. I am unable to resolve a service which has a dependency on This works (as it has done for years!)
With the following Service definition
In the reproduction steps I am unable to take a Service which has a dependency on Reproduction Steps
Expected behaviorThe keyed service which has been registered with the name "simple" is resolved and returned from the Actual behaviorException thrown:
Regression?No response Known WorkaroundsNo response ConfigurationNo response Other informationNo response
|
Note the repro above does not require transient services; singleton repros as well. @benjaminpetit I believe |
We didn't expected the user to use But I guess we could add it to the list of "built in services", like we do today for |
Oh I see what you mean with the extension methods targeting If you change the dependency to be Please see example below.
As the above compiles, however when it runs it throws the error:
|
It was fixed here: #89509, I don't repro this issue with a more recent build. |
@benjaminpetit does that also relate to the extension method being on the |
Sorry if I wasn't clear:
|
No worries :-) So injecting IServiceProvider is still the expected injectable interface but the extension methods to resolve keyed services on it should now work. Do we know if there will be a patch to preview 7 or will this be rolled into preview 8? Thanks for taking the time to look at this :-) |
No backport for preview 7 was done, it will be included in the next preview release. |
Closing as by design (must inject |
In case anyone else stumbles across this issue in preview 7 Andrew Lock demonstrates it well in this blog post - https://andrewlock.net/exploring-the-dotnet-8-preview-keyed-services-dependency-injection-support/#limitations-with-the-current-implementation |
Description
The update to dependency injection to allow for Keyed Services really interested me so I had a play.
I am unable to resolve a service which has a dependency on
IKeyedServiceProvider
to then try and resolve a named dependency at runtime.This works (as it has done for years!)
With the following Service definition
In the reproduction steps I am unable to take a Service which has a dependency on
IKeyedServiceProvider
as it does not appear to be automatically registered when the service provider is built in the same way theIServiceProvider
is registered.Reproduction Steps
Expected behavior
The keyed service which has been registered with the name "simple" is resolved and returned from the
GetService
method on theSimpleParentWithDynamicKeyedService
instance.Actual behavior
Exception thrown:
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: