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