Closed kl1mm closed 8 months ago
How would MediatR support keyed services? Typically when I use keyed services, I don't inject them. I instead resolve them directly from the composition root (the scoped IServiceProvider).
Ah just adding a keyed service causes this issue? That seems strange, that an accessor throws this exception.
Yep, this is what broke it: https://github.com/dotnet/runtime/pull/87183/files#diff-90a4b966bf74781df1f355057ad5adca90af0211e46c659965ce745fb0594b5dR157
I don't support keyed services, so I suppose I'll have to explicitly check to see if it's a keyed service and skip them. Annoying.
Hey @jbogard, yes it's not that MediatR supports Keyedservices but that the two can coexist in one application.
When I´m right ServiceDescriptor class has a property called IsKeyedService - maybe this helps.
mMilk
Yeah that's what I'll have to do. Luckily that property is public!
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.
I just ran into this and came to file this issue 😄. Assembly scanning is convenient but often fragile 😞.
Are there any current workarounds to use both the keyed services feature and mediatr? It doesn't appear possible otherwise.
@Dulatr use the MyGet feed. The latest is on RC1.
Realized I didn't push, give it a few minutes and it'll be RC2.
@jbogard thanks for the response!
Sorry I've never used MyGet before, what's the feed url?
There's a link in the readme but you can find it here: https://myget.org/gallery/mediatr-ci
If I was motivated I probably could have put prerelease packages up on NuGet. But like I said. Motivated.
Good afternoon, is there any news on solving the problem?
I am facing the same issue but more strange is: I am not using any Keyed service in my Azure Functions project.
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 MediatR.Registration.ServiceRegistrar.RegisterBehaviorIfImplementationsExist.
It seems that the ImplementationType property of ServiceDescriptor is accessed which is not allowed in the case of a "keyed" ServiceDescriptor.
maybe this helps to prepare MediatR for .NET8 KeyedServices?
cheers mMilk
Example to reproduce