Questions tagged [zenject]

Dependency Injection Framework for Unity3D

For further details, see https://github.com/modesttree/Zenject

76 questions
1
vote
0 answers

how to inject dependency in already created object when it comes to zenject?

I already have created a object by Activator.CreateInstance(). How can I inject dependency that object having? As a reference, I use c# and zenject of Unity3d. public abstract class Task { [Inject(Id = "Json")] protected ISerializer…
Dennis
  • 130
  • 10
1
vote
1 answer

ZenjectUnitTestFixture is not recreating singletons after [Setup]

I am writing unit tests for Extenject (Zenject) and using ZenjectUnitTestFixture but it looks like some of my singletons are not being recreated after test [Setup]. I have set breakpoints and checked that the Container registrations are being…
1
vote
1 answer

ZenjectException: Unable to resolve 'A'. Object graph:

I'm getting a ZenjectException: Unable to resolve 'Facade'. Object graph: error that I can't understand. I've been following this example but I can't get my code to work. I have a prefab with the following components: Facade FacadeInstaller Game…
Daniele
  • 153
  • 3
  • 11
1
vote
1 answer

Inject into additive loaded scene in Unity with zenject

How can I inject dependencies into an additively loaded scene with zenject?
1
vote
0 answers

Can c# custom attribute implement subscribe/unsubscribe methods?

I'm using Zenject, but this can apply to other frameworks as well. I'm not thrilled with boiler-plate code that i have to copy/paste all over. In this case, OnEnable should subscribe to a signal, OnDisable should unsubscribe. Can an attribute be…
Dave A.
  • 43
  • 5
1
vote
1 answer

Zenject inject plain class into Monobehaviour

I'm trying to inject plain C# class into Mobobehaviour, but an "Unable to resolve 'HeightSystem' while building object with type 'UserDirijible'. Object graph: UserDirijible" exception is thrown. namespace Systems { public class HeightSystem …
wingear
  • 819
  • 9
  • 21
1
vote
1 answer

How to bind a list of non-MonoBehaviour objects to manager class using Zenject

I am using Zenject for dependency injection in my game, and I am in an impasse. Let me describe my current setup: I have several characters with their own GameObjectContext and CharacterInstaller responsible for injecting a CharacterController into…
Hellium
  • 7,206
  • 2
  • 19
  • 49
1
vote
1 answer

How to inject MonoBehaviour class to non Monobehaviour in Unity3d with zenject?

I want to organize my code as well as I can, but I have some trouble with its organization. I try to use SOLID principles and make separate entities. I want to use MVVM to view (unity-weld as well), and DI container (zenject as well). It's my first…
1
vote
1 answer

Instantiating random or chosen prefabs with sub-container thru Factory or Pool

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. What I want to do is the same as in this code sample from Zenject documentation, but…
earthQuake
  • 106
  • 3
  • 11
1
vote
1 answer

Is it possible to inject a component that doesn't have a prefab/GameObject associated with it?

I have a game object (a cube, let's say) which exists in the scene, and I want it to have an injectable component. I want to be able to say, for example: My cube has an IShotFirer member, which can resolve to either a BoomShotFirer or a…
vargonian
  • 3,064
  • 3
  • 27
  • 36
1
vote
1 answer

Multiple calls for method binding in Zenject

I have a MonoBehaviour that uses method injection : [Inject] private void Init(IFirst first, ISecond second) { _first = first; _second = second; StartService(); Debug.LogError("Should only appear once!"); …
friday
  • 1,358
  • 1
  • 14
  • 23
1
vote
0 answers

Zenject Unity3D testing scene hit "unable to resolve class" how to get rid of?

I have SceneA (A) and SceneB (B). The B has also a Foo AsSingle and NonLazy installed by the SceneContext Installer. The Foo has an IInitialize implemented to Debog.Log("Hello Errors!"): yield return LoadScene("SceneA"); yield return new…
Ariam1
  • 1,673
  • 2
  • 13
  • 32
1
vote
1 answer

Zenject Unity testing scene - how navigate next scene, having container updated to new SceneContext properly?

How to switch scene during scene test, in a class extending SceneTestFixture? I need to make a test case while extending SceneTestFixture , where during the test I load Scene 'A' and it set a condition to ProjectContext and then in the same test…
Ariam1
  • 1,673
  • 2
  • 13
  • 32
1
vote
1 answer

Swap between multiple instances of ScriptableObjectInstaller procedurally

The documentation says that you can easily swap between multiple ScriptableObjectInstallers. And i think you do this by assigning needed ScriptableObjectInstaller of a same class in SceneContext. But what if i want to procedurally decide which…
earthQuake
  • 106
  • 3
  • 11
1
vote
1 answer

FromNewComponentSibling and then reuse

Container.Bind() .To() .FromNewComponentSibling() .WhenInjectedInto(); Container.Bind() .FromResolve(); I want the same instance of…
Alexandr
  • 3,859
  • 5
  • 32
  • 56