C#C
C#3y ago
Noriega

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:
serviceCollection.AddKeyedSingleton<IScraper, BooruScraper>("booru");
serviceCollection.AddKeyedSingleton<IScraper, HIScraper>("hi");

Exception:
- System.InvalidOperationException: This service descriptor is keyed. Your service provider may not support keyed services. 
Was this page helpful?