Mathijs-Bakker / Extenject

Dependency Injection Framework for Unity Game Engine
MIT License
531 stars 97 forks source link

Passing data to prefab created by factory, using game object context #39

Open nipunasudha opened 2 years ago

nipunasudha commented 2 years ago

Describe the bug When using PrefabFactory or InstantiatePrefabForComponent through a custom factory, the framework implies that additional data can be passed to the facade/installer. However, if the object contains a game object context, Zenject failes to resolve the passed parameters.

To Reproduce

  1. Make a binding like Container.BindFactory<UnityEngine.Object, float, MyFacade, MyFacade.Factory>().FromFactory<PrefabFactory<float, MyFacade>>();
  2. Pass the data on creation myFactory.Create(prefab, 2f)
  3. Zenject fails to resolve the float if the given prefab has a game object context attached.

Steps to reproduce the behavior:

Expected behavior Data can be passed dynamically to prefab factories or custom factories that get a prefab at run time.

Extenject and Unity info (please complete the following information):

Additional context Noticed that doing the binding like:

Container.BindFactory<float, MyFacade, MyFacade.Factory>().FromSubContainerResolve().ByNewContextPrefab(...)

makes it work. However in our case it's not good enough, as we want to pass the prefab (and the data) along in run time.