Stashbox by Peter Csajtai

<PackageReference Include="Stashbox" Version="5.0.0-preview-717" />

 NameRule

using Stashbox.Resolution; namespace Stashbox.Registration.SelectionRules { internal class NameRule : IRegistrationSelectionRule { public bool IsValidForCurrentRequest(TypeInformation typeInformation, ServiceRegistration registration, ResolutionContext resolutionContext) { if (typeInformation.DependencyName != null && registration.RegistrationContext.Name != null && !registration.RegistrationContext.Name.Equals(typeInformation.DependencyName) && !resolutionContext.CurrentContainerContext.ContainerConfiguration.NamedDependencyResolutionForUnNamedRequestsEnabled) return false; if (typeInformation.DependencyName == null && registration.RegistrationContext.Name != null) return resolutionContext.CurrentContainerContext.ContainerConfiguration.NamedDependencyResolutionForUnNamedRequestsEnabled; return true; } public bool ShouldIncrementWeight(TypeInformation typeInformation, ServiceRegistration registration, ResolutionContext resolutionContext) { if (typeInformation.DependencyName != null && registration.RegistrationContext.Name != null) return registration.RegistrationContext.Name.Equals(typeInformation.DependencyName); return false; } } }