diff --git a/VContainer/Assets/Tests/ContainerTest.cs b/VContainer/Assets/Tests/ContainerTest.cs index 635d6618..6e5e86b1 100644 --- a/VContainer/Assets/Tests/ContainerTest.cs +++ b/VContainer/Assets/Tests/ContainerTest.cs @@ -617,6 +617,31 @@ public void OnContainerDisposeCallback() Assert.That(resolvedJustBeforeDispose2, Is.Not.Null); } + [Test] + public void OnContainerDisposeCallback_ParentChild() + { + var parentDisposeCalled = false; + var childDisposeCalled = false; + + var builder = new ContainerBuilder(); + builder.Register(Lifetime.Scoped); + + builder.RegisterDisposeCallback(x => parentDisposeCalled = true); + + var container = builder.Build(); + + var childContainer = container.CreateScope(childBuilder => + { + childBuilder.Register(Lifetime.Scoped); + childBuilder.RegisterDisposeCallback(x => childDisposeCalled = true); + }); + + childContainer.Dispose(); + + Assert.That(childDisposeCalled, Is.True); + Assert.That(parentDisposeCalled, Is.False); + } + [Test] public void TryResolveTransient() { diff --git a/VContainer/Assets/VContainer/Runtime/ContainerBuilderExtensions.cs b/VContainer/Assets/VContainer/Runtime/ContainerBuilderExtensions.cs index e82d7ade..fd8f71bb 100644 --- a/VContainer/Assets/VContainer/Runtime/ContainerBuilderExtensions.cs +++ b/VContainer/Assets/VContainer/Runtime/ContainerBuilderExtensions.cs @@ -143,8 +143,8 @@ public static RegistrationBuilder RegisterFactory callback) { - builder.Register(container => new BuilderCallbackDisposable(callback, container), Lifetime.Scoped); - builder.RegisterBuildCallback(container => container.Resolve>()); + builder.Register(container => new BuilderCallbackDisposable(callback, container), Lifetime.Singleton); + builder.RegisterBuildCallback(container => container.Resolve>>()); } [Obsolete("IObjectResolver is registered by default. This method does nothing.")]