hadashiA / VContainer

The extra fast, minimum code size, GC-free DI (Dependency Injection) library running on Unity Game Engine.
https://vcontainer.hadashikick.jp
MIT License
1.88k stars 163 forks source link

Injecting into MonoBehaviours Issues #615

Closed sartubakia closed 4 months ago

sartubakia commented 7 months ago

When i call InjectGameObject in parent object to inject in to child objects, it leads to error if child object depends on parent

For example

WindowsManager.cs [Inject] void Construct(LifeTimeScope scope) { Scope.Container.InjectGameObject(panel.gameObject); } --(var 1) Panel.cs [Inject] void Construct(LifeTimeScope scope , WindowsManager windowsManager) { //THIS IS LEAD TO ERROR InvalidOperationException: ValueFactory attempted to access the Value property of this instance. } --(var 2) [Inject] void Construct(LifeTimeScope scope ) { //NO ERRORS ALL FINE }

sartubakia commented 7 months ago

UPD: InjectGameObjects only works from start without errors, not even awake

DenisPimenov commented 7 months ago

I think this is expected behavior. The container cannot pass the parent object to the child object because the parent is in the "construction" phase. But maybe a more detailed error message is needed.