From 228fe8256f9d70adac6894892fdbaeca7b383426 Mon Sep 17 00:00:00 2001 From: Thien Nguyen Date: Sun, 31 May 2026 22:58:16 +0700 Subject: [PATCH] refactor(LifetimeScope): change MonoBehaviour AutoInjectAll method call order - change SetContainer build callback to the start of container build configuration - separate AutoInjectAll method from SetContainer and set AutoInjectAll as the last container built callback --- .../Assets/VContainer/Runtime/Unity/LifetimeScope.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/VContainer/Assets/VContainer/Runtime/Unity/LifetimeScope.cs b/VContainer/Assets/VContainer/Runtime/Unity/LifetimeScope.cs index 88c7a82d..3d6d9676 100644 --- a/VContainer/Assets/VContainer/Runtime/Unity/LifetimeScope.cs +++ b/VContainer/Assets/VContainer/Runtime/Unity/LifetimeScope.cs @@ -202,7 +202,6 @@ public void Build() // ReSharper disable once PossibleNullReferenceException Parent.Container.CreateScope(builder => { - builder.RegisterBuildCallback(SetContainer); builder.ApplicationOrigin = this; builder.Diagnostics = VContainerSettings.DiagnosticsEnabled ? DiagnositcsContext.GetCollector(scopeName) : null; InstallTo(builder); @@ -215,7 +214,6 @@ public void Build() ApplicationOrigin = this, Diagnostics = VContainerSettings.DiagnosticsEnabled ? DiagnositcsContext.GetCollector(scopeName) : null, }; - builder.RegisterBuildCallback(SetContainer); InstallTo(builder); builder.Build(); } @@ -226,7 +224,6 @@ public void Build() void SetContainer(IObjectResolver container) { Container = container; - AutoInjectAll(); } public TScope CreateChild(IInstaller installer = null, string childScopeName = null) @@ -287,8 +284,8 @@ public TScope CreateChildFromPrefab(TScope prefab, Action(this).AsSelf(); + builder.RegisterBuildCallback(AutoInjectAll); EntryPointsBuilder.EnsureDispatcherRegistered(builder); } @@ -356,7 +354,7 @@ LifetimeScope GetRuntimeParent() return null; } - void AutoInjectAll() + void AutoInjectAll(IObjectResolver container) { if (autoInjectGameObjects == null) return;