VContainer icon indicating copy to clipboard operation
VContainer copied to clipboard

Injecting into MonoBehaviours Issues

Open sartubakia opened this issue 1 year ago • 2 comments

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 avatar Jan 13 '24 12:01 sartubakia

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

sartubakia avatar Jan 13 '24 12:01 sartubakia

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.

DenisPimenov avatar Jan 13 '24 20:01 DenisPimenov