ssannandeji / Zenject-2019

Dependency Injection Framework for Unity3D
MIT License
2.53k stars 366 forks source link

Objects which class with interface implemented couldn't be inject correctly #684

Open gary9716 opened 3 years ago

gary9716 commented 3 years ago

Hi, recently I found out that some objects which class that has interface implemented would not able to correctly get the dependencies from scene context.(dependencies from project content can be perfectly resolved without any hassle.) For example, I have a class called EquipCardCtrler. It has Monohaviour class as base and ISlotItem as interface. One of its dependencies is called PrefabMgr. This dependency is dynamically bound in difference scenes. It would always cause error when those objects which classes with interface implemented got injected. It said a sort of message like the dependency graph cannot be resolved. I solved this issue by casting the object into its base class and then injecting. For example: .... var ctrler = aGameObj.GetComponent< EquipCardCtrler >(); diContainer.Inject(ctrler as MonoBehaviour); ....

Hope this can help someone who struggle with same issue.