From 3e1846f3c9263aea1eef7d581d249f1209abe928 Mon Sep 17 00:00:00 2001 From: Akeit0 <90429982+Akeit0@users.noreply.github.com> Date: Tue, 25 Jun 2024 01:40:48 +0900 Subject: [PATCH] Fix unintended multiple registration Fixed multiple registrations which occurs when the scope has grand- parent. --- .../InstanceProviders/CollectionInstanceProvider.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/VContainer/Assets/VContainer/Runtime/Internal/InstanceProviders/CollectionInstanceProvider.cs b/VContainer/Assets/VContainer/Runtime/Internal/InstanceProviders/CollectionInstanceProvider.cs index 5532c376..404782c1 100644 --- a/VContainer/Assets/VContainer/Runtime/Internal/InstanceProviders/CollectionInstanceProvider.cs +++ b/VContainer/Assets/VContainer/Runtime/Internal/InstanceProviders/CollectionInstanceProvider.cs @@ -98,8 +98,11 @@ internal void CollectFromParentScopes( if (scope.TryGetRegistration(finderType, out var registration) && registration.Provider is CollectionInstanceProvider parentCollection) { - mergedRegistrations = mergedRegistrations ?? ListPool.Get(); - mergedRegistrations.AddRange(registrations); + if (mergedRegistrations == null) + { + mergedRegistrations = ListPool.Get(); + mergedRegistrations.AddRange(registrations); + } if (localScopeOnly) {