From a77bc9db773c0601bceaaa49a21bb72c2878bb14 Mon Sep 17 00:00:00 2001 From: A F <49113047+arty-F@users.noreply.github.com> Date: Sun, 9 Jun 2024 21:31:48 +0700 Subject: [PATCH 1/3] Update README.md --- README.md | 53 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 649df88..2db2802 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Fast and easy to use dependency injection library for Unity game engine. - **Property** injection. - **Method** injection. - Injection lifetime. +- Local scope injection. ## Installation @@ -50,9 +51,7 @@ public class TestClass } ``` -2. Inject instances by invoking `Inject()` method. You can use generic version of `Inject<>()` method on `GameObject` where the generic type parameter will represent the type of `GameObject` component that needs to be injected. You can also specify the lifetime of the injection: -- `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. +2. Inject instances by invoking `Inject()` method. You can use generic version of `Inject<>()` method on `GameObject` where the generic type parameter will represent the type of `GameObject` component that needs to be injected. ```csharp using UniDI; ... @@ -69,11 +68,11 @@ gameObjectInstance1.GetComponent().Inject(); //good way GameObject component injecting var gameObjectInstance2 = Instantiate(_gameObjectPrefab); -gameObjectInstance2.Inject(Lifetime.Game); +gameObjectInstance2.Inject(); //best way GameObject component injecting InjectedComponent typedInstance = Instantiate(_typedPrefab); -typedInstance.Inject(Lifetime.Scene); +typedInstance.Inject(); ``` 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). @@ -98,6 +97,50 @@ GameObject gameObjectInstance2 = _gameObjectPrefab.InstantiateResolve Date: Sun, 9 Jun 2024 21:33:25 +0700 Subject: [PATCH 2/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2db2802..62b4655 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ By default, all injected classes will be placed in the global scope. In order to public class Consumer : MonoBehaviour { [Inject] private GlobalInjectionClass _field1; - [Inject] public LocalInjectionClass _field2; + [Inject] private LocalInjectionClass _field2; } ... int id = consumer.GetInstanceID(); From a84c396259b56ed3ab09d869fb77821c38ad3a8b Mon Sep 17 00:00:00 2001 From: A F <49113047+arty-F@users.noreply.github.com> Date: Sun, 9 Jun 2024 21:35:33 +0700 Subject: [PATCH 3/3] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 62b4655..24ee50e 100644 --- a/README.md +++ b/README.md @@ -136,9 +136,9 @@ You can override or clear previously injected dependencies. For overriding just - Global scope dependency clearing by `ReleaseDependency()`. - Local scope dependency clearing by `ReleaseDependency(id)` where `id` is a local scope `int` type identifier. By default this type of clear deletes the entire local scope. To avoid completely clearing the local scope you must pass a value of `clearFullScope` is `false`, like that `ReleaseDependency(id, false)`. By passing this `false` value you will clear only the type on which this method was called in the specified local scope. ```csharp -globalDependencyInstance.ReleaseDependency(); //clear the type of globalDependencyInstance in global scope +globalDependencyInstance.ReleaseDependency(); //clear globalDependencyInstance in global scope localDependencyInstance1.ReleaseDependency(id); //clear all dependencies in specified local scope -localDependencyInstance2.ReleaseDependency(id, false); //clear only the type of localDependencyInstance2 in specified local scope +localDependencyInstance2.ReleaseDependency(id, false); //clear localDependencyInstance2 in specified local scope ``` ## Performance