You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Unity.Entities;
using VContainer;
using VContainer.Unity;
public class NewTestScript
{
private static IEnumerable<World> Worlds
{
get
{
foreach (var world in World.All)
{
yield return world;
}
}
}
public static IEnumerable<TestCaseData> TestCases => new[]
{
new TestCaseData((Action<IContainerBuilder>)(builder =>
{
builder.RegisterNewWorld("test", Lifetime.Scoped);
builder.RegisterSystemIntoWorld<TestSystem>("test");
builder.Register<Test1>(Lifetime.Transient);
})).SetName("New World"),
new TestCaseData((Action<IContainerBuilder>)(builder =>
{
builder.RegisterSystemIntoDefaultWorld<TestSystem>();
builder.Register<Test1>(Lifetime.Transient);
})).SetName("Default World"),
};
[Test]
[TestCaseSource(nameof(TestCases))]
public void EntitySystemLifetime(Action<IContainerBuilder> configuration)
{
using (var scope = LifetimeScope.Create(configuration))
{
Assert.NotNull(scope.Container.Resolve(typeof(Test1)));
Assert.IsFalse(Worlds.All(world => world.GetExistingSystem<TestSystem>() == SystemHandle.Null), "generated");
}
// After exiting LifetimeScope, it is assumed that the items registered in the container will be deleted.
Assert.IsTrue(Worlds.All(world => world.GetExistingSystem<TestSystem>() == SystemHandle.Null), "LifetimeScope exited.");
}
}
[DisableAutoCreation]
public partial class TestSystem : SystemBase
{
protected override void OnUpdate()
{
}
}
public class Test1
{
[Inject]
public Test1(TestSystem testSystem) { }
}
The lifespan of a System appears to be tied to the World, not the container.
Versions
Unity 2022.3.26f1
VContainer 1.16.2
Entities 1.2.4
The text was updated successfully, but these errors were encountered:
I ran the code below in Play Mode test:
The lifespan of a System appears to be tied to the World, not the container.
Versions
The text was updated successfully, but these errors were encountered: