diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b8b1c83..09f5e9fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - `WhenResolutionPathHas()` & `WhenInResolutionPathOf()` registration options for handling more conditional resolution cases. They extend the original *parent type* and *attribute* conditions with inheritance. +### Fixed +- Name comparison during named scope resolution. + ## [v5.5.3] - 2022-11-29 ### Fixed - `IsRegistered()` produced falsy results on requests with dynamically constructed string service names. diff --git a/src/Lifetime/NamedScopeLifetime.cs b/src/Lifetime/NamedScopeLifetime.cs index ecfa412d..aa6ad35d 100644 --- a/src/Lifetime/NamedScopeLifetime.cs +++ b/src/Lifetime/NamedScopeLifetime.cs @@ -45,7 +45,7 @@ private static object GetScopedValue(IResolutionScope currentScope, IRequestCont Func factory, Type serviceType, int scopeId, object scopeName) { var scope = currentScope; - while (scope != null && scope.Name != scopeName) + while (scope != null && !scopeName.Equals(scope.Name)) scope = scope.ParentScope; if (scope == null) diff --git a/src/Registration/SelectionRules/ScopeNameRule.cs b/src/Registration/SelectionRules/ScopeNameRule.cs index c01ebfae..9ee715c2 100644 --- a/src/Registration/SelectionRules/ScopeNameRule.cs +++ b/src/Registration/SelectionRules/ScopeNameRule.cs @@ -18,7 +18,7 @@ public bool IsValidForCurrentRequest(TypeInformation typeInformation, if (resolutionContext.ScopeNames.Length == 0) return false; - shouldIncrementWeight = resolutionContext.ScopeNames.First() == namedScopeLifetime.ScopeName; + shouldIncrementWeight = resolutionContext.ScopeNames.First().Equals(namedScopeLifetime.ScopeName); return resolutionContext.ScopeNames.Contains(namedScopeLifetime.ScopeName); } } diff --git a/test/NamedScopeTests.cs b/test/NamedScopeTests.cs index 6977c615..b55a2753 100644 --- a/test/NamedScopeTests.cs +++ b/test/NamedScopeTests.cs @@ -16,11 +16,12 @@ public class NamedScopeTests [ClassData(typeof(CompilerTypeTestData))] public void NamedScope_Simple_Resolve_Prefer_Named(CompilerType compilerType) { + var name = "A".ToLower(); var inst = new StashboxContainer(config => config.WithCompiler(compilerType)) .Register() - .Register(config => config.InNamedScope("A")) + .Register(config => config.InNamedScope(name)) .Register() - .BeginScope("A") + .BeginScope(name) .Resolve(); Assert.IsType(inst);