Stashbox by Peter Csajtai

<PackageReference Include="Stashbox" Version="3.4.1-preview-605" />

 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; } } }