zenject

Layered architecture by Zenject's DiContainers with flat GameObjectContext hierarchy


Previous question: link

In my application I have three layers:

image

How can I setup Game Object Context that Model layer will include all Data layer dependencies and Presentation layer will include all Model&Data layers dependencies?

Is there any way to set parent component for Game Object Context?


Solution

  • You can add a GameObjectContext by right clicking in the Scene Hierarchy and selecting Zenject -> GameObjectContext. You can add one for data, model, and presentation. Then you just have to set the transform parents up the same way you want the container parents to be. From your description I think you probably want it like this:

    enter image description here

    Then you can add each installer by attaching a MonoInstaller to each context. You an also do all this dynamically using a FromSubContainerResolve inside a SceneContext installer as well, if you prefer.