Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing dynamic data + prefab through method Create (Factory) while that prefab has GameObjectContext #280

Open
lucid-dreamm opened this issue Jan 6, 2023 · 1 comment

Comments

@lucid-dreamm
Copy link

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>>();
@SimonNordon4
Copy link

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);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants