Stashbox by Peter Csajtai

<PackageReference Include="Stashbox" Version="5.8.1" />

 ScopeNameRule

using Stashbox.Lifetime; using Stashbox.Resolution; using System.Runtime.CompilerServices; namespace Stashbox.Registration.SelectionRules { internal class ScopeNameRule : IRegistrationSelectionRule { [System.Runtime.CompilerServices.NullableContext(1)] public bool IsValidForCurrentRequest(TypeInformation typeInformation, ServiceRegistration registration, ResolutionContext resolutionContext, out bool shouldIncrementWeight) { NamedScopeLifetime namedScopeLifetime = registration.Lifetime as NamedScopeLifetime; if (namedScopeLifetime == null) { shouldIncrementWeight = false; return true; } shouldIncrementWeight = false; if (resolutionContext.ScopeNames.Length == 0) return false; shouldIncrementWeight = resolutionContext.ScopeNames.First().Equals(namedScopeLifetime.ScopeName); return resolutionContext.ScopeNames.Contains(namedScopeLifetime.ScopeName); } } }