Zenject
Zenject copied to clipboard
Passing dynamic data + prefab through method Create (Factory) while that prefab has GameObjectContext
Hey, I would like to be able to pass dynamic data + prefab through method Create (Factory) while that prefab has GameObjectContext (Installer). In this situation, it seems zenject cannot inject dynamic data and it fails while without GameObjectContext, it works.
_factory.Create(prefab,data)
In scene context
Container.BindFactory<Object, SpawnModuleData, ModuleFacade, ModuleFacade.Factory>()
.FromFactory<PrefabFactory<SpawnModuleData, ModuleFacade>>();
Try this instead:
Container.BindFactory<Object, SpawnModuleData, ModuleFacade, ModuleFacade.Factory>()
.ResolveFromSubContainer().ByNewPrefabInstaller<YourInstaller>(prefabInstance);
Inside YourInstaller, you will inject the instances you're passing in.
public class YourInstaller : Installer
{
[Inject]private SpawnModuleData _data;
public override void InstallBindings()
{
Container.Bind<ModuleFacade>.AsSingle();
Container.Bind.FromInstance(_data);
}
}