From 149f659acdd171695123a8be1c23ccdb82d76503 Mon Sep 17 00:00:00 2001 From: A F <49113047+arty-F@users.noreply.github.com> Date: Tue, 28 May 2024 21:13:13 +0700 Subject: [PATCH 1/2] Update README.md --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a559a9a..12330f7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# MonoInjector +# UniDI Fast and easy to use dependency injection library for Unity game engine. @@ -13,18 +13,19 @@ Fast and easy to use dependency injection library for Unity game engine. - **Field** injection. - **Property** injection. - **Method** injection. +- Injection lifetime. ## Installation ### Install from git URL -Requires a version of unity that supports path query parameter for git packages (Unity 2021.3 or later). You can add a reference `https://github.com/arty-F/MonoInjector.git?path=Assets/MonoInjector` to Package Manager. +Requires a version of unity that supports path query parameter for git packages (Unity 2021.3 or later). You can add a reference `https://github.com/arty-F/UniDI.git?path=Assets/UniDI` to Package Manager. ![Screenshot_1](https://github.com/arty-F/MonoInjector/assets/49113047/0a65d9e3-89f2-44ed-8232-713660590d6f) ### Install from .unitypackage -Download the latest `.unitypackage` file from [releases](https://github.com/arty-F/MonoInjector/releases) page and import downloaded package into unity. +Download the latest `.unitypackage` file from [releases](https://github.com/arty-F/UniDI/releases) page and import downloaded package into unity. ![Screenshot_2](https://github.com/arty-F/MonoInjector/assets/49113047/4bb02ea9-bd94-4ab4-8d73-54a64661e2d8) @@ -32,7 +33,7 @@ Download the latest `.unitypackage` file from [releases](https://github.com/arty 1. Mark field/property/method into which the dependency should be injected with the `[Inject]` attribute. ```csharp -using MonoInjector; +using UniDI; public class TestClass { [Inject] private InjectedClass1 _injectedField; @@ -53,7 +54,7 @@ public class TestClass - `Lifetime.Game` (default) : the dependency will exist as long as the application is running. - `Lifetime.Scene` : dependencies will be cleared every time the active scene changes. ```csharp -using MonoInjector; +using UniDI; ... [SerializeField] GameObject _gameObjectPrefab; [SerializeField] MyComponent _typedPrefab; @@ -77,7 +78,7 @@ typedInstance.Inject(Lifetime.Scene); 3. Resolve dependencies of injection consumer classes by invoking `Resolve()` method. Or you can use `GameObject` extension method on prefab to one row instantiate and resolving dependencies (has 9 overloads like original Instantiate method). ```csharp -using MonoInjector; +using UniDI; ... [SerializeField] GameObject _gameObjectPrefab; [SerializeField] MyComponent _typedPrefab; From 9563747a2eff65237da40109d96a75466b878d25 Mon Sep 17 00:00:00 2001 From: A F <49113047+arty-F@users.noreply.github.com> Date: Wed, 29 May 2024 22:46:25 +0700 Subject: [PATCH 2/2] Update README.md --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 12330f7..649df88 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ public class TestClass using UniDI; ... [SerializeField] GameObject _gameObjectPrefab; -[SerializeField] MyComponent _typedPrefab; +[SerializeField] InjectedComponent _typedPrefab; ... //plain C# class injecting var csharpClass = new InjectedClass(); @@ -65,14 +65,14 @@ csharpClass.Inject(); //bad way GameObject component injecting var gameObjectInstance1 = Instantiate(_gameObjectPrefab); -gameObjectInstance1.GetComponent().Inject(); +gameObjectInstance1.GetComponent().Inject(); //good way GameObject component injecting var gameObjectInstance2 = Instantiate(_gameObjectPrefab); -gameObjectInstance2.Inject(Lifetime.Game); +gameObjectInstance2.Inject(Lifetime.Game); //best way GameObject component injecting -var typedInstance = Instantiate(_typedPrefab); +InjectedComponent typedInstance = Instantiate(_typedPrefab); typedInstance.Inject(Lifetime.Scene); ``` @@ -81,7 +81,7 @@ typedInstance.Inject(Lifetime.Scene); using UniDI; ... [SerializeField] GameObject _gameObjectPrefab; -[SerializeField] MyComponent _typedPrefab; +[SerializeField] ConsumerComponent _typedPrefab; ... //plain C# class resolving var csharpClass = new TestClass(); @@ -89,13 +89,13 @@ csharpClass.Resolve(); //bad way GameObject resolving GameObject gameObjectInstance1 = Instantiate(_gameObjectPrefab); -gameObjectInstance1.GetComponent().Resolve(); +gameObjectInstance1.GetComponent().Resolve(); //good way GameObject resolving -GameObject gameObjectInstance2 = _gameObjectPrefab.InstantiateResolve(); +GameObject gameObjectInstance2 = _gameObjectPrefab.InstantiateResolve(); //best way GameObject resolving -MyComponent typedInstance = _typedPrefab.InstantiateResolve(position, rotation); +ConsumerComponent typedInstance = _typedPrefab.InstantiateResolve(position, rotation); ``` ## Performance