Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject before awake when instantiating #575

Merged
merged 3 commits into from
Dec 23, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Added Unit Test validating prefab returns to original state
  • Loading branch information
AlonTalmi committed Nov 15, 2023
commit c11730c77dff0e4e41415f7838f9a87afcb1b663
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using NUnit.Framework;
using UnityEngine;
using VContainer.Unity;
Expand Down Expand Up @@ -141,6 +142,22 @@ void AssertInstantiatedInstance(SampleMonoBehaviour instance)
}
}

[Test]
public void Instantiate_ExceptionThrownDuringInjection_PrefabIsStillEnabled()
{
var builder = new ContainerBuilder();

var original = new GameObject("Original").AddComponent<SampleMonoBehaviour>();

//Throws in resolving
builder.Register<ServiceA>(_ => throw new(), Lifetime.Singleton);

var container = builder.Build();

Assert.Throws<Exception>(() => container.Instantiate(original));
Assert.That(original.gameObject.activeSelf, Is.True);
}

[Test]
public void ReenterInjectGameObject()
{
Expand Down