diff --git a/Runtime/Context/SceneContext.cs b/Runtime/Context/SceneContext.cs index 01dd7da..668bb1b 100644 --- a/Runtime/Context/SceneContext.cs +++ b/Runtime/Context/SceneContext.cs @@ -131,6 +131,7 @@ await Task.WhenAll(injectableComponents.Select(x await Shutdown(); return; } + throw; } using (new ContextSpaceScope(this)) { diff --git a/Runtime/DIContainer.cs b/Runtime/DIContainer.cs index 77e1bd2..257bc41 100644 --- a/Runtime/DIContainer.cs +++ b/Runtime/DIContainer.cs @@ -272,8 +272,16 @@ Component component if (go.GetComponent(typeof(IGameObjectContextRoot))) return instance; - foreach (var component in go.GetComponentsInChildren(typeof(IInjectableComponent))) - await InjectIntoAsync(component, args); + try + { + foreach (var component in go.GetComponentsInChildren(typeof(IInjectableComponent))) + await InjectIntoAsync(component, args); + } + catch (Exception e) + { + Object.Destroy(prefabInstance); + throw e; + } return instance; }