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