fix: don't handle scoped services in ServiceManager.UnloadAllServices()

Fixes a deadlock while unloading
This commit is contained in:
goat 2023-05-22 21:24:17 +02:00
parent b80681e3e1
commit 34bb2a7ad4
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B

View file

@ -309,6 +309,13 @@ internal static class ServiceManager
if (!serviceType.IsAssignableTo(typeof(IServiceType)))
continue;
// Scoped services shall never be unloaded here.
// Their lifetime must be managed by the IServiceScope that owns them. If it leaks, it's their fault.
if (serviceType.GetServiceKind() == ServiceKind.ScopedService)
continue;
Log.Verbose("Calling GetDependencyServices for '{ServiceName}'", serviceType.FullName!);
dependencyServicesMap[serviceType] =
((List<Type>)typeof(Service<>)
.MakeGenericType(serviceType)