AutoInject icon indicating copy to clipboard operation
AutoInject copied to clipboard

Feature Request: An `IsResolved` property/method to be included to check if a node has had it's dependencies resolved

Open Soren025 opened this issue 7 months ago • 0 comments

One thing I find my self doing is the following structure.

[Meta(typeof(IDependent))]
public partial class Foo: Node
{
    [Dependency]
    public Bar Bar => this.DependOn<Bar>();
    
    private bool IsResolved { get; set; }
    
    public override void _Notification(int what)
    {
        this.Notify(what);
    }

    public void OnResolved()
    {
        Bar.SomeEvent += OnSomeEvent;
        IsResolved = true;
    }

    public override void _ExitTree()
    {
        if (IsResolved)
        {
            Bar.SomeEvent -= OnSomeEvent;
        }
    }

    private void OnSomeEvent() { }
}

Foo wants to unregister events from a dependency when it's removed from it's parent, but if it's removed before OnResolved() is called it might result in errors due to an unresolved dependency. So I have found the need to add a bool property to check if OnResolved() has been called.

Soren025 avatar Jul 06 '25 17:07 Soren025