Godot.DependencyInjection icon indicating copy to clipboard operation
Godot.DependencyInjection copied to clipboard

[Docs/Feedback] Injected members are unusable at `_on_ready`

Open Fernthedev opened this issue 10 months ago • 3 comments

DependencyInjectionManagerNode injects all nodes at the Ready stage.

This is called first to children, then to their parents. Because of this, all nodes have their fields set to null even if the services are defined properly.

Not entirely sure what's the intended way of doing this, maybe you thought we should use this instead. Regardless, seems pretty easy to solve.

[Inject]
public void _ReadyInject() {}
Unrelated but would be nice to have more Node dependency support, similar to how Zenject for Unity works. E.g adding nodes existing in the scene tree to the ServiceCollection automatically, their interfaces etc.

I made my own solution which adds nodes in the tree implementing IServiceNode to the service collection.

Edit: The workaround shown above won't work for injected fields or properties. Fields and properties are not injected at the time the [Inject] method is called, but parameters are.

Fernthedev avatar Aug 20 '23 01:08 Fernthedev