forked from ssannandeji/Zenject-2019
-
Notifications
You must be signed in to change notification settings - Fork 299
Open
Description
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");
}
}
}
Metadata
Metadata
Assignees
Labels
No labels