title: Instantiating random or chosen prefabs with sub-container thru Factory or Pool
body: <p>I have an array of prefabs and I want to be able to Instantiate randomly picked prefabs thru Zenject Factory and perform their bindings in their sub-containers. </p>
  
  <p>What I want to do is the same as in this code sample from Zenject documentation, but for randomly selected prefabs.
  <a href="https://github.com/modesttree/Zenject/blob/master/Documentation/SubContainers.md#using-game-object-contexts-no-monobehaviours" rel="nofollow noreferrer">https://github.com/modesttree/Zenject/blob/master/Documentation/SubContainers.md#using-game-object-contexts-no-monobehaviours</a></p>
  
  <pre><code>using UnityEngine;
  using Zenject;
  
  public class GameInstaller : MonoInstaller
  {
      [SerializeField]
      GameObject ShipPrefab;
  
      public override void InstallBindings()
      {
          Container.BindInterfacesTo&lt;GameRunner&gt;().AsSingle();
  
          Container.BindFactory&lt;float, ShipFacade, ShipFacade.Factory&gt;()
              .FromSubContainerResolve().ByNewPrefabInstaller&lt;ShipInstaller&gt;(ShipPrefab);
      }
  }
  </code></pre>
  
  <p>I was able to partially make it work with </p>
  
  <pre><code>[SerializeField] private GameObject[] ships;
  
  ...
  
  Container.BindFactory&lt;float, ShipFacade, ShipFacade.Factory&gt;()
              .FromSubContainerResolve().ByNewGameObjectMethod(SpawnShip);
  
  ...
  
  private void SpawnShip(DiContainer container, float speed)
  {
      container.Bind&lt;ShipFacade&gt;().AsSingle();
      container.Bind&lt;Transform&gt;().FromComponentOnRoot();
      var shipPrefab = ships[Random.Range(0, ships.Length)];
      var ship = container.InstantiatePrefab(shipPrefab);
      container.Bind&lt;ShipHealthHandler&gt;().FromNewComponentOn(ship).WhenInjectedInto&lt;ShipFacade&gt;();
      container.BindInstance(speed).WhenInjectedInto&lt;ShipInputHandler&gt;();
  }
  </code></pre>
  
  <p>But it's awkward and in this case I guess I'm not using an advantage of sub-container. And also prefabs spawns in an empty GameObject. 
  What I want to achieve is to be able to use ShipInstaller for sub-container binding.</p>