SceneDiDefinition05 / 13

Scene dependencies and Scene DI

Specify how to create a service and when to start it.

SceneDiDefinition describes the dependencies for one scene. Its key must match the key in scenes.map.

GameSceneDi has two separate lists. Here is a shortened example for one service. scene.di.ts

protected override registerProviders(registrar: ValuesGroupRegistrar): void {
  registrar.singletonClass(BlockPuzzleServices.Audio, BlockPuzzleAudioService);
}

protected override registerServices(services: SceneServiceTokenRegistry): void {
  services.add(BlockPuzzleServices.Audio);
}

registerProviders specifies how to create the service. In registerServices, list the services whose entry and exit methods the SDK should call.

Shared across the gameGlobal DI

Systems · progress · behavior factories

boot sceneLoading
game sceneGameplay · Geometry · Audio
The child container looks for a local registration first, then asks its parent.

Geometry only calculates coordinates. We can request it by token even when it is absent from registerServices.

GameDiDefinition combines the registrations for the game and its scenes. The SDK checks the scene keys and verifies that each service has a registration.

Sources ↗

Block Puzzle · scene.di.ts↗Geometry without lifecycle hooks and active scene services.