Stashbox by Peter Csajtai

<PackageReference Include="Stashbox" Version="4.2.0-preview-687" />

 ScopeNameRule

using Stashbox.Resolution; namespace Stashbox.Registration.SelectionRules { internal class ScopeNameRule : IRegistrationSelectionRule { public bool IsValidForCurrentRequest(TypeInformation typeInformation, ServiceRegistration registration, ResolutionContext resolutionContext) { if (resolutionContext.ScopeNames.Length == 0 && registration.HasScopeName) return false; if (resolutionContext.ScopeNames.Length != 0 && registration.HasScopeName) return resolutionContext.ScopeNames.Contains(registration.NamedScopeRestrictionIdentifier); return true; } public bool ShouldIncrementWeight(TypeInformation typeInformation, ServiceRegistration registration, ResolutionContext resolutionContext) { if (resolutionContext.ScopeNames.Length != 0 && registration.HasScopeName) return resolutionContext.ScopeNames.First() == registration.NamedScopeRestrictionIdentifier; return false; } } }