ssannandeji / Zenject-2019

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

Interfaces and FromComponentInNewPrefab #666

Open ut2496 opened 4 years ago

ut2496 commented 4 years ago

I recently shifted from Zenject v5.4 to Zenject 6+. I understand that using AsSingle across multiple statements is not suitable anymore, I have been able to adapt the changes in most cases barring the following with interfaces.

I used the following way to install certain bindings while using v5.4

Container.Bind<IFoo>().To<Foo>().FromComponentInNewPrefab(Prefab).AsSingle(); Container.Bind<IBar>().To<Bar>().FromComponentInNewPrefab(Prefab).AsSingle();

This used to only create a single instance of Prefab. But in Zenject 6+ it creates a duplicate Prefab too. Switching the latter to AsCached doesn't work either.

Since Interfaces are binding to different ResultType I cant do something like this either: Container.Bind<typeof(IFoo), typeof(IBar)>().To<Z>().FromComponentInNewPrefab(Prefab).AsSingle();

Is this the intended behavior now ? If Yes, then Is there a way now to get the same behavior as present in v5.4 ?