Skip to content

Commit be9691d

Browse files
authored
Merge pull request #77 from KuraiAndras/feature/fix-disposals
Fix disposals in unity
2 parents 6aa3482 + 1bf2ef4 commit be9691d

File tree

16 files changed

+194
-108
lines changed

16 files changed

+194
-108
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# 7.0.0
2+
- Add `MonoBehaviourInjected` and `MonoBehaviourScoped`
3+
- Renamed classes: \*MonoBehavior\* -> \*MonoBehavio**u**r\*
4+
- InjectedMonoBehavior now removes Scope from the store during `OnDestroy`
5+
- ScopeStore is now generic
26
- Update dependencies
37
- Update minimum Unity version to `2020.3`
48
- Update to .NET 6 where not breaking

MainProject/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<LangVersion>9.0</LangVersion>
44
<Nullable>enable</Nullable>
55

6-
<CurrentVersion>6.1.2</CurrentVersion>
6+
<CurrentVersion>7.0.0</CurrentVersion>
77

88
<Version>$(CurrentVersion)</Version>
99
<PakcageVersion>$(CurrentVersion)</PakcageVersion>

MainProject/Injecter/IScopeStore.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ namespace Injecter
44
{
55
public interface IScopeStore
66
{
7-
IServiceScope CreateScope(object owner);
8-
void DisposeScope(object owner);
9-
IServiceScope GetScope(object owner);
7+
IServiceScope CreateScope<T>(T owner) where T : notnull;
8+
void DisposeScope<T>(T owner) where T : notnull;
9+
IServiceScope? GetScope<T>(T owner) where T : notnull;
1010
}
1111
}

MainProject/Injecter/ScopeStore.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,30 @@ public sealed class ScopeStore : IScopeStore
1111

1212
public ScopeStore(IServiceProvider serviceProvider) => _serviceProvider = serviceProvider;
1313

14-
public IServiceScope CreateScope(object owner)
14+
public IServiceScope CreateScope<T>(T owner) where T : notnull
1515
{
16+
if (owner == null) throw new ArgumentNullException(nameof(owner));
17+
1618
var scope = _serviceProvider.CreateScope();
1719
_scopes.Add(owner, scope);
1820

1921
return scope;
2022
}
2123

22-
public IServiceScope GetScope(object owner) => _scopes[owner];
24+
public IServiceScope? GetScope<T>(T owner) where T : notnull
25+
{
26+
if (owner == null) throw new ArgumentNullException(nameof(owner));
27+
28+
_scopes.TryGetValue(owner, out var scope);
2329

24-
public void DisposeScope(object owner)
30+
return scope;
31+
}
32+
33+
public void DisposeScope<T>(T owner) where T : notnull
2534
{
26-
var scope = _scopes[owner];
35+
if (owner == null) throw new ArgumentNullException(nameof(owner));
36+
37+
if (!_scopes.TryGetValue(owner, out var scope)) return;
2738

2839
scope.Dispose();
2940

UnityProject/Injecter.Unity/Assets/Injecter.Hosting.Unity/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.injecter.hosting.unity",
3-
"version": "6.1.2",
3+
"version": "7.0.0",
44
"displayName": "Injecter.Hosting.Unity",
55
"license": "MIT",
66
"licensesUrl": "https://github.com/KuraiAndras/Injecter/blob/master/LICENSE.md",
@@ -13,6 +13,6 @@
1313
"url": "https://github.com/KuraiAndras/Injecter"
1414
},
1515
"dependencies": {
16-
"com.injecter.unity": "6.1.2"
16+
"com.injecter.unity": "7.0.0"
1717
}
1818
}

UnityProject/Injecter.Unity/Assets/Injecter.Unity.Tests/Arrange/DisposeIsCalledOnDestroy/DisposingScript.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ namespace Injecter.Unity.Tests.Arrange.DisposeIsCalledOnDestroy
44
{
55
public sealed class DisposingScript : MonoBehaviour
66
{
7-
[Inject] private readonly ITestDisposable _testDisposable;
7+
[Inject]
8+
[System.Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0051:Remove unused private members", Justification = "Used for test")]
9+
private readonly ITestDisposable _testDisposable;
810
}
911
}

UnityProject/Injecter.Unity/Assets/Injecter.Unity/ComponentMissingException.cs

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

UnityProject/Injecter.Unity/Assets/Injecter.Unity/ComponentMissingException.cs.meta

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

UnityProject/Injecter.Unity/Assets/Injecter.Unity/ISceneInjector.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public interface ISceneInjector
2525
/// Sets up usages of the InjectAttribute
2626
/// </summary>
2727
/// <exception cref="System.ArgumentNullException"/>
28-
/// <exception cref="ComponentMissingException"/>
2928
/// <param name="gameObjectInstance">GameObject instance to inject into</param>
3029
/// <param name="createScopes">Create new scopes</param>
3130
/// <returns>Original instance</returns>

UnityProject/Injecter.Unity/Assets/Injecter.Unity/InjectedMonoBehaviorT.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
namespace Injecter.Unity
55
{
6-
public abstract class InjectedMonoBehavior<TViewModel> : InjectedMonoBehavior
6+
public abstract class InjectedMonoBehaviour<TViewModel> : InjectedMonoBehaviour
77
{
8-
protected InjectedMonoBehavior(bool createScopes) : base(createScopes)
8+
protected InjectedMonoBehaviour(bool createScopes) : base(createScopes)
99
{
1010
}
1111

0 commit comments

Comments
 (0)