Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ITickable and IInitializable to be Created from factory or instantiated from Container #294

Open
Battou2501 opened this issue Feb 14, 2025 · 0 comments

Comments

@Battou2501
Copy link

Battou2501 commented Feb 14, 2025

I need to be able to create instances of classes that implement ITickable and so they Tick method will be properly called after that.
Right now any way of creating instances and/or binding them using Container do not trigger execution of their Tick method.

I have tried next classes and methods of creating instances. None of them trigger Tick or Initialize.

public class TestZenTick : MonoBehaviour
{
    private DiContainer _container;
    private TestTickable.Factory _factory;
    
    [Inject]
    private void Construct(DiContainer container, TestTickable.Factory factory)
    {
        _container = container;
        _factory = factory;
    }
    
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        if (_factory == null || _container == null) return;

        var t = new  TestTickable();
        _container.BindInterfacesAndSelfTo<TestTickable>().FromInstance(t).AsSingle().NonLazy();
        _factory.Create();
        _container.Instantiate<TestTickable>();
        _container.BindInterfacesAndSelfTo<TestTickable>().FromFactory<TestTickable,TestTickable.Factory>().NonLazy();
        _container.BindInterfacesAndSelfTo<TestTickable>().FromNew().NonLazy();
    }

    public class TestTickable : ITickable, IInitializable
    {
        public void Tick()
        {
            Debug.Log("Tick");
        }
        
        public class Factory : PlaceholderFactory<TestTickable> { }

        public void Initialize()
        {
            Debug.Log("Initialize");
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant