Stashbox by Peter Csajtai

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

 NameRule

using Stashbox.Entity; using Stashbox.Resolution; namespace Stashbox.Registration.SelectionRules { internal class NameRule : IRegistrationSelectionRule { public bool IsValidForCurrentRequest(TypeInformation typeInformation, IServiceRegistration registration, ResolutionContext resolutionContext) { if (typeInformation.DependencyName != null && !registration.RegistrationName.Equals(typeInformation.DependencyName) && !registration.IsResolvableByUnnamedRequest) return false; if (typeInformation.DependencyName == null) return registration.IsResolvableByUnnamedRequest; return true; } public bool ShouldIncrementWeight(TypeInformation typeInformation, IServiceRegistration registration, ResolutionContext resolutionContext) { if (typeInformation.DependencyName != null) return registration.RegistrationName.Equals(typeInformation.DependencyName); return false; } } }