Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
arty-F authored May 29, 2024
1 parent 149f659 commit 9563747
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,22 @@ public class TestClass
using UniDI;
...
[SerializeField] GameObject _gameObjectPrefab;
[SerializeField] MyComponent _typedPrefab;
[SerializeField] InjectedComponent _typedPrefab;
...
//plain C# class injecting
var csharpClass = new InjectedClass();
csharpClass.Inject();

//bad way GameObject component injecting
var gameObjectInstance1 = Instantiate(_gameObjectPrefab);
gameObjectInstance1.GetComponent<MyComponent>().Inject();
gameObjectInstance1.GetComponent<InjectedComponent>().Inject();

//good way GameObject component injecting
var gameObjectInstance2 = Instantiate(_gameObjectPrefab);
gameObjectInstance2.Inject<MyComponent>(Lifetime.Game);
gameObjectInstance2.Inject<InjectedComponent>(Lifetime.Game);

//best way GameObject component injecting
var typedInstance = Instantiate(_typedPrefab);
InjectedComponent typedInstance = Instantiate(_typedPrefab);
typedInstance.Inject(Lifetime.Scene);
```

Expand All @@ -81,21 +81,21 @@ typedInstance.Inject(Lifetime.Scene);
using UniDI;
...
[SerializeField] GameObject _gameObjectPrefab;
[SerializeField] MyComponent _typedPrefab;
[SerializeField] ConsumerComponent _typedPrefab;
...
//plain C# class resolving
var csharpClass = new TestClass();
csharpClass.Resolve();

//bad way GameObject resolving
GameObject gameObjectInstance1 = Instantiate(_gameObjectPrefab);
gameObjectInstance1.GetComponent<MyComponent>().Resolve();
gameObjectInstance1.GetComponent<ConsumerComponent>().Resolve();

//good way GameObject resolving
GameObject gameObjectInstance2 = _gameObjectPrefab.InstantiateResolve<MyComponent>();
GameObject gameObjectInstance2 = _gameObjectPrefab.InstantiateResolve<ConsumerComponent>();

//best way GameObject resolving
MyComponent typedInstance = _typedPrefab.InstantiateResolve(position, rotation);
ConsumerComponent typedInstance = _typedPrefab.InstantiateResolve(position, rotation);
```

## Performance
Expand Down

0 comments on commit 9563747

Please sign in to comment.