Skip to content

Commit 0d2b96b

Browse files
committed
refactor: ScopeContainer
1 parent 9329cde commit 0d2b96b

File tree

5 files changed

+12
-44
lines changed

5 files changed

+12
-44
lines changed

src/NestedDIContainer/Runtime/DependencyBinder.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Linq;
43

54
namespace TanitakaTech.NestedDIContainer
65
{
76
public readonly ref struct DependencyBinder
87
{
9-
private readonly ScopeId _scopeId;
10-
private readonly Dictionary<ScopeId, IScope> _scopes;
118
private readonly ScopeContainer _scopeContainer;
129

13-
public DependencyBinder(ScopeId scopeId, Dictionary<ScopeId, IScope> scopes, ScopeContainer scopeContainer)
10+
public DependencyBinder(ScopeContainer scopeContainer)
1411
{
15-
_scopeId = scopeId;
16-
_scopes = scopes;
1712
_scopeContainer = scopeContainer;
1813
}
1914

2015
public void ExtendScope(IExtendScope scope)
2116
{
22-
_scopeContainer.Inject(scope, GlobalProjectScope.Scopes[_scopeId]);
17+
_scopeContainer.Inject(scope);
2318
scope.Construct(this);
2419
}
2520

src/NestedDIContainer/Runtime/GlobalProjectScope.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/NestedDIContainer/Runtime/GlobalProjectScope.cs.meta

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/NestedDIContainer/Runtime/IScope.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
public interface IScope : IInjectable
44
{
55
void Construct(DependencyBinder binder, object config);
6+
ScopeId ScopeId { get; }
67
ScopeId? ParentScopeId { get; }
78
ScopeContainer ScopeContainer { get; }
89
}

src/NestedDIContainer/Runtime/ScopeContainer.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ namespace TanitakaTech.NestedDIContainer
88
public class ScopeContainer
99
{
1010
private readonly Dictionary<IntPtr, object> _value = new Dictionary<IntPtr, object>();
11-
private readonly ScopeId _scopeId;
11+
private readonly IScope _scope;
1212
private readonly ScopeContainer _parentScopeContainer;
13-
public ScopeId ScopeId => _scopeId;
14-
public ScopeId? ParentScopeId => _parentScopeContainer?.ScopeId;
13+
public IScope Scope => _scope;
14+
public IScope ParentScope => _parentScopeContainer?.Scope;
1515

16-
public ScopeContainer(ScopeId scopeId, ScopeContainer parentScopeContainer)
16+
public ScopeContainer(IScope scope, ScopeContainer parentScopeContainer)
1717
{
18-
_scopeId = scopeId;
18+
_scope = scope;
1919
_parentScopeContainer = parentScopeContainer;
2020
}
21-
21+
2222
public void Bind(Type type, object module)
2323
{
2424
var key = type.TypeHandle.Value;
2525
if (!_value.TryAdd(key, module))
2626
{
27-
throw new ConstructException($"Module already exists: {type}, {_scopeId}");
27+
throw new ConstructException($"Module already exists: {type}, {_scope}");
2828
}
2929
}
3030

@@ -59,7 +59,7 @@ public object Resolve(Type type)
5959
}
6060

6161
private const BindingFlags MemberBindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly;
62-
public void Inject(object injectableObject, IScope scope)
62+
public void Inject(object injectableObject)
6363
{
6464
var type = injectableObject.GetType();
6565
var fields = type.GetFields(MemberBindingFlags);
@@ -78,7 +78,7 @@ public void Inject(object injectableObject, IScope scope)
7878
var injectAttr = prop.GetCustomAttribute<InjectAttribute>();
7979
if (injectAttr != null)
8080
{
81-
prop.SetValue(scope, Resolve(prop.PropertyType));
81+
prop.SetValue(Scope, Resolve(prop.PropertyType));
8282
}
8383
}
8484
}

0 commit comments

Comments
 (0)