ssannandeji / Zenject-2019

Dependency Injection Framework for Unity3D
MIT License
2.52k stars 363 forks source link

OnInstantiate callback not consistently called #584

Closed hendrik-schulte closed 5 years ago

hendrik-schulte commented 5 years ago

Hey folks,

Im instantiating a prefab using the following code:

Container
    .Bind(typeof(SomeClass), typeof(ISomeInterface))
    .FromComponentsInNewPrefab(prefab)
    .WithGameObjectName(prefab.name)
    .AsCached()
    .OnInstantiated((c, instance) => OnInstantiated(instance as SomeClass))
    .NonLazy();

However, the OnInstantiated callback is not called! When changing the second line to the follwowing, it works just fine.

Container
    .BindInterfacesAndSelfTo<SomeClass>()
    .FromComponentsInNewPrefab(prefab)
    .WithGameObjectName(prefab.name)
    .AsCached()
    .OnInstantiated((c, instance) => OnInstantiated(instance as SomeClass))
    .NonLazy();

I think this is not intended behaviour. I'm on Zenject 7.3.1 and Unity 2018.2.7f1.

Thank you and keep up the great work!

svermeulen commented 5 years ago

Should be fixed now, thanks for the report