-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathScope.cs
More file actions
64 lines (53 loc) · 1.53 KB
/
Copy pathScope.cs
File metadata and controls
64 lines (53 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Pure.DI;
using UnityEngine;
// ReSharper disable InconsistentNaming
// ReSharper disable RequiredBaseTypesIsNotInherited
// ReSharper disable ClassNeverInstantiated.Global
// ReSharper disable Unity.RedundantSerializeFieldAttribute
// ReSharper disable ArrangeTypeMemberModifiers
// ReSharper disable UnusedMember.Local
internal class ClocksComposition
{
[SerializeField] private ClockConfig clockConfig;
void Setup() => DI.Setup(kind: CompositionKind.Internal)
.Transient(() => clockConfig)
.Singleton<ClockService>();
}
public partial class Scope : MonoBehaviour
{
[SerializeField] private Scope parentScope;
private bool isReady;
void Setup() => DI.Setup()
.Hint(Hint.ScopeMethodName, "SetupScope")
.DependsOn(nameof(ClocksComposition), SetupContextKind.Members)
.Bind<IClockSession>().As(Lifetime.Scoped).To<ClockSession>()
.Root<ClockManager>(nameof(ClockManager))
.Builders<MonoBehaviour>();
public void EnsureReady()
{
if (isReady)
{
return;
}
if (parentScope != null && !ReferenceEquals(parentScope, this))
{
parentScope.EnsureReady();
SetupScope(parentScope, this);
}
isReady = true;
Debug.Log($"Scene '{gameObject.scene.name}' Pure.DI scope is ready on '{name}'.");
}
void Awake()
{
EnsureReady();
}
void Start()
{
EnsureReady();
ClockManager.Start();
}
void OnDestroy()
{
Dispose();
}
}