Dependency Injection and UniInject - UltraStar-Deluxe/Play GitHub Wiki

UltraStar Play uses the UniInject project for dependency injection. You can find an introduction and basic exmples on its GitHub page.

UniInject in UltraStar Play

SceneInjectionManager

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.

Binding

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.