-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from KuraiAndras/feature/add-inhertiance-inje…
…ction 9.1.0
- Loading branch information
Showing
9 changed files
with
105 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
UnityProject/Injecter.Unity/Assets/Injecter.Hosting.Unity/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
UnityProject/Injecter.Unity/Assets/Injecter.Unity/MonoBehaviourInjected.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using UnityEngine; | ||
|
||
namespace Injecter.Unity | ||
{ | ||
/// <summary> | ||
/// Inheriting from this class will inject everything marked with the <see cref="InjectAttribute"/> | ||
/// </summary> | ||
public abstract class MonoBehaviourInjected : MonoBehaviour | ||
{ | ||
[Inject] private IScopeStore _store; | ||
|
||
protected IServiceScope Scope { get; private set; } | ||
|
||
/// <summary> | ||
/// Call the base function before accessing injected members | ||
/// </summary> | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Roslynator", "RCS1213:Remove unused member declaration.", Justification = "Unity method")] | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0079:Remove unnecessary suppression", Justification = "Unity method")] | ||
protected virtual void Awake() => Scope = CompositionRoot.ServiceProvider.GetRequiredService<IInjecter>().InjectIntoType(this, true); | ||
|
||
/// <summary> | ||
/// Call the base function after accessing injected members | ||
/// </summary> | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Roslynator", "RCS1213:Remove unused member declaration.", Justification = "Unity method")] | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0079:Remove unnecessary suppression", Justification = "Unity method")] | ||
protected virtual void OnDestroy() | ||
{ | ||
_store.DisposeScope(this); | ||
|
||
Scope = null; | ||
_store = null; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
UnityProject/Injecter.Unity/Assets/Injecter.Unity/MonoBehaviourInjected.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters