Fix unguarded calls to ServiceDescriptor.ImplementationType for keyed services (#16604)

* Update integration test base class to verify that calls to ServiceDescriptor.ImplementationType are guarded for keyed services

* Fix unguarded calls to ServiceDescriptor.ImplementationType for keyed services
This commit is contained in:
Josh Brown
2024-06-22 10:20:12 +01:00
committed by GitHub
parent de74ae4c04
commit cb090353f4
6 changed files with 11 additions and 5 deletions

View File

@@ -136,6 +136,12 @@ public abstract class UmbracoIntegrationTest : UmbracoIntegrationTestBase
services.AddLogger(webHostEnvironment, Configuration);
// Register a keyed service to verify that all calls to ServiceDescriptor.ImplementationType
// are guarded by checking IsKeyedService first.
// Failure to check this when accessing a keyed service descriptor's ImplementationType property
// throws a InvalidOperationException.
services.AddKeyedSingleton<object>("key");
// Add it!
var hostingEnvironment = TestHelper.GetHostingEnvironment();
var typeLoader = services.AddTypeLoader(