-
-
Notifications
You must be signed in to change notification settings - Fork 75
Dependency Injection and UniInject
UltraStar Play uses the UniInject project for dependency injection. You can find an introduction and basic exmples on its GitHub page.
The SceneInjectionManager is one of our CommonSceneObjects.
It is taking care of finding IBinder instances in the scene and injecting the bound objects into all scripts that implement the INeedInjection interface. This is done in Awake(), such that injection is complete when the Start() method is entered.
There is the CommonSceneObjectsBinder, which is one of the CommonSceneObjects itself. This IBinder instance is taking care of binding objects such as the SettingsManager, ThemeManager, etc.
Another IBinder instance is typically the "...Controller" class for a scene. It binds scene-specific objects. This way, scene-specific objects are only set once in the Controller class (via the Unity Inspector), bound there, and then injected where needed in the scene.
The SingScene is an example of a more complex injection context. Each PlayerController creates a new Injector and binds player-specific objects. For example, the PlayerProfile and MicProfile are added to this Injector. These objects are then injected into the player-specific instances of UI classes, microphone recording classes, etc.
Did you found what you're looking for? If you still got questions look into ❔Common FAQ or go to 💬UltraStar Play Discord. There is also a 👋🏻central help desk of UltraStar/Vocaluxe/Performous-Community on Discord.