Skip to content

Commit 0ab0a5f

Browse files
update ScopedEagerInitializationTests
1 parent 5f0f527 commit 0ab0a5f

1 file changed

Lines changed: 19 additions & 20 deletions

File tree

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
using NUnit.Framework;
1+
using System.Collections.Generic;
2+
using FluentAssertions;
3+
using NUnit.Framework;
24
using Reflex.Core;
35
using Reflex.Enums;
4-
using UnityEngine;
56
using Resolution = Reflex.Enums.Resolution;
67

78
namespace Reflex.EditModeTests
@@ -10,32 +11,30 @@ public class ScopedEagerInitializationTests
1011
{
1112
class ScopedService
1213
{
14+
public static List<ScopedService> Instances { get; private set; } = new();
15+
1316
public ScopedService()
1417
{
15-
Debug.Log($"ScopedService {GetHashCode()} created.");
18+
Instances.Add(this);
1619
}
1720
}
18-
21+
1922
[Test]
20-
public void Foo()
23+
public void EnsureScopedEagerInstancesAreConstructedAsSoonAsContainerIsBuilt()
2124
{
22-
var containerBuilder = new ContainerBuilder()
23-
.RegisterType(typeof(ScopedService), Lifetime.Scoped, Resolution.Lazy);
24-
25-
// containerBuilder.OnContainerBuilt += OnContainerBuilt;
26-
//
27-
// void OnContainerBuilt(Container c)
28-
// {
29-
// containerBuilder.OnContainerBuilt -= OnContainerBuilt;
30-
// c.Resolve<ScopedService>();
31-
// c.OnContainerScoped += OnContainerBuilt;
32-
// }
25+
ScopedService.Instances.Clear();
26+
27+
var builder = new ContainerBuilder().RegisterType(typeof(ScopedService), Lifetime.Scoped, Resolution.Eager);
28+
ScopedService.Instances.Count.Should().Be(0);
29+
30+
var containerA = builder.Build();
31+
ScopedService.Instances.Count.Should().Be(1);
3332

34-
var container = containerBuilder.Build();
35-
var scoped1 = container.Scope();
36-
var scoped2 = container.Scope();
33+
var scoped0 = containerA.Scope();
34+
var scoped1 = containerA.Scope();
35+
var scoped2 = scoped1.Scope();
3736
var scoped3 = scoped2.Scope();
38-
var scoped4 = scoped3.Scope();
37+
ScopedService.Instances.Count.Should().Be(5);
3938
}
4039
}
4140
}

0 commit comments

Comments
 (0)