modesttree / Zenject

Dependency Injection Framework for Unity3D
MIT License
2.52k stars 273 forks source link

The parameter is not injected by the PrefabResourceFactory #174

Open kennir opened 4 years ago

kennir commented 4 years ago

Example code here:

public class EnemyFacade: MonoBehaviour {
   [Inject]
   public void Construct(int value) { 
     Debug.Log(value);
   } 

   public class Factory : PlaceholderFactory<string, int, EnemyFacade> { }
}

TestInstaller 

public override void InstallBindings() {
  Container.BindFactory<string, int, EnemyFacade, EnemyFacade.Factory>()
    .FromFactory<PrefabResourceFactory<int, EnemyFacade>>();
}

Create enemyFacade by factory

_factory.Create(prefabResource, 1)

I got error

ZenjectException: Unable to resolve 'int' while building object with type 'EnemyFacade'. Object graph:
DefaultGameObjectKernel
EnemyFacade

so How to pass value into facade ?

falkura commented 1 month ago

https://github.com/modesttree/Zenject/blob/master/Documentation/Factories.md#example