diff --git a/VContainer/Assets/VContainer/Runtime/Internal/FixedTypeKeyHashTableRegistry.cs b/VContainer/Assets/VContainer/Runtime/Internal/FixedTypeKeyHashTableRegistry.cs index d0a0e052..3399ae9e 100644 --- a/VContainer/Assets/VContainer/Runtime/Internal/FixedTypeKeyHashTableRegistry.cs +++ b/VContainer/Assets/VContainer/Runtime/Internal/FixedTypeKeyHashTableRegistry.cs @@ -59,6 +59,9 @@ static void AddToBuildBuffer(IDictionary buf, Type service, AddCollectionToBuildBuffer(buf, collection); } collection.Add(registration); + + // Overwritten by the later registration + buf[service] = registration; } else { diff --git a/VContainer/Assets/VContainer/Tests/ContainerTest.cs b/VContainer/Assets/VContainer/Tests/ContainerTest.cs index 4ade2c22..1fec11d2 100644 --- a/VContainer/Assets/VContainer/Tests/ContainerTest.cs +++ b/VContainer/Assets/VContainer/Tests/ContainerTest.cs @@ -197,6 +197,24 @@ public void ResolveCollection() Assert.That(empty, Is.Empty); } + [Test] + public void ResolveLastOneWhenConflicted() + { + var builder = new ContainerBuilder(); + builder.Register(Lifetime.Transient); + builder.Register(Lifetime.Transient); + + builder.Register(Lifetime.Transient); + builder.Register(Lifetime.Transient); + builder.Register(Lifetime.Transient); + + var container = builder.Build(); + var i1 = container.Resolve(); + var i3 = container.Resolve(); + Assert.That(i1, Is.InstanceOf()); + Assert.That(i3, Is.InstanceOf()); + } + [Test] public void ResolveOnceAsCollection() {