Exception when attempting to use keyed dependencies
I tried making use of the new keyed DI feature that comes with net 8, but when I try injecting 2 dependencies with
IServiceCollection.AddKeyedSingleton<T1, T2>("")
, Im receiving an exception that I havent found any fix for. this kind of setup for dependencies doesn't seem to require any special setup according to the example on the microsoft page, so im confused
Code:
Exception:
10 Replies
This can happen if you have a service that does assembly scanning, similar to https://github.com/jbogard/MediatR/issues/942
GitHub
System.InvalidOperationException with KeyedServices in .NET 8 · Iss...
Hi, I'm currently playing with the new .NET 8 Preview 7 that came out a few days ago. When I add a KeyedService to the DI container, it causes a System.InvalidOperationException thrown by Media...
Well my exception has nothing to do with mediatr, but do you mean if Im using reflection while registering dependencies?
If you, or someone else is, then potentially
got it
do you have any ideas for registering 2 dependencies with the same interface, other than directly registering the implemented class?
full stack would help a little more
keyed should work, but it really depends on a lot of things. The stack at least can help identify the source of the issue
seems to be the following line when I register a gql server
yea, likely the GraphQL library broke and will need to have something similar to this line https://github.com/jbogard/MediatR/blob/6baaeef7a16ca75cb905829f870f79c6334ef40e/src/MediatR/Registration/ServiceRegistrar.cs#L273
GitHub
MediatR/src/MediatR/Registration/ServiceRegistrar.cs at 6baaeef7a16...
Simple, unambitious mediator implementation in .NET - jbogard/MediatR
that happened in the net8 runtime change https://github.com/dotnet/runtime/pull/87183/files#diff-90a4b966bf74781df1f355057ad5adca90af0211e46c659965ce745fb0594b5dR157
GitHub
Add Keyed Services Support to Dependency Injection by benjaminpetit...
Related issue: #64427
Since my last proposal (https://gist.github.com/benjaminpetit/49a6b01692d0089b1d0d14558017efbc) we made some changes and took some decisions.
This PR is still in draft, but ev...
so you're doing the right thing, the library you're using isn't
@Andrew (ryzngard | they/them) I was meant to update on this way earlier, but i needed to update a graphql package in my project
turns out I was supposed to update it from nuget