Reputation: 1011
I'm well aware this might not be the best place to ask a Zenject question. I've already posted the same question on Zenject google groups page as well. I'm posting this here thinking that someone who is on here (who's not on google groups) might be able to help me out.
I have a question about Zenject Global Bindings.
My AR app at the moment have several different screens (saved as scenes). Each scene can be run on it's own that way I could keep it very compartmentalised. When I press a button on 'Screen1' it loads 'Screen2' so on and so forth. I'm using a very basic AppDelegate which contains a NavigationController class which handled all the UGUI transitions so that it appears as a normal iOS navigation based app so to speak. I'm injecting AppDelegate as Singleton on all the installers I have but since there are individual CompositionRoots for individual screens (scenes), globally they are not injected as singletons.
Is there a way to do this. Have a singleton injection all throughout the app but with different composition roots?
If not, how to use Global composition root? I've followed instructions on the guide to create a global composition root and add the installer as a prefab and all that. I deleted installer from the scene as well. But when I play nothing happens. Am I missing something obvious here.
Thanks in advance.
Upvotes: 2
Views: 6283
Reputation: 171
in your Resources folder create a project context prefab how to make a project context prefab.
You also absolutely have to include a "SceneContext" in your scene. this spawns the first "ProjectContext".
After the creation of said object, it will load on any scene start. along with the installers and scriptable object installers provided on the prefab. along with bindings to singletons ie:
Container.Bind<IFoo>().To<Foo>().AsSingle().NonLazy();
this means, on zenject initilization you will have an instance of your singelton ready and waiting.
Upvotes: 7