If we use the FromKeyedServices
attribute in a class library and the keyed registration is missing, it falls back to the default dependency injection behavior and gets the last registered implementation. However, If we use FromKeyedServices
directly in a Minimal API endpoint handler and the key does not exist, it throws an exception.
This repo contains some examples that showcase all the different scenarios. Every endpoint comes with a description of the particular behavior it refers to.
The issue has been solved in .NET 8.0.11.