Stashbox by Peter Csajtai

<PackageReference Include="Stashbox" Version="5.10.1-preview-812" />

 ConditionRule

using Stashbox.Resolution; using System.Collections.Generic; using System.Runtime.CompilerServices; namespace Stashbox.Registration.SelectionRules { internal class ConditionRule : IRegistrationSelectionRule { [System.Runtime.CompilerServices.NullableContext(1)] public bool IsValidForCurrentRequest(TypeInformation typeInformation, ServiceRegistration registration, ResolutionContext resolutionContext, out bool shouldIncrementWeight) { ConditionOptions orDefault = registration.Options.GetOrDefault<ConditionOptions>(RegistrationOption.ConditionOptions); if (orDefault != null) { shouldIncrementWeight = ServiceRegistration.IsUsableForCurrentContext(typeInformation, orDefault); return shouldIncrementWeight; } shouldIncrementWeight = false; return orDefault == null; } } }