Stashbox by Peter Csajtai

<PackageReference Include="Stashbox" Version="3.1.0-preview-542" />

 ScopeNameRule

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